File size: 5,547 Bytes
6c95da8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document Translator - IA Edition</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
    <style>

        body {

            background: linear-gradient(135deg, #1e3c72, #2a5298);

            color: white;

            text-align: center;

            padding: 40px;

        }

        .container {

            max-width: 600px;

            background: rgba(255, 255, 255, 0.1);

            padding: 20px;

            border-radius: 15px;

            backdrop-filter: blur(10px);

            box-shadow: 0px 0px 15px rgba(255, 255, 255, 0.2);

        }

        .result-box {

            background: white;

            color: black;

            padding: 15px;

            border-radius: 10px;

            text-align: left;

            max-height: 300px;

            overflow-y: auto;

            margin-top: 15px;

            font-size: 16px;

        }

    </style>
</head>
<body>
    <div class="container">
        <h1>📝 AI Document Translator</h1>
        <p class="file-info">Formats supportés : <b>TXT, PDF, DOCX, PPTX, XLSX</b></p>
        
        <form id="uploadForm">
            <input type="file" id="fileInput" name="file" class="form-control mt-3" required>
            
            <select id="src_lang" name="src_lang" class="form-control mt-3">
                <option >Francais</option>
                <option >Anglais</option>
                <option >Arabe</option>
                <option >Espagnol</option>
            </select>
            <select id="tgt_lang" name="tgt_lang" class="form-control mt-3">
                <option >Francais</option>
                <option >Anglais</option>
                <option >Arabe</option>
                <option >Espagnol</option>
            </select>
            
            <button type="submit" class="btn btn-success mt-3">Traduire</button>
        </form>

        <div class="menu mt-3">
            <button type="button" class="btn btn-info" id="openFile">📂 Ouvrir le fichier</button>
            <button id="copyText" class="btn btn-secondary" disabled>📋 Copier</button>
            <button id="speakText" class="btn btn-dark" disabled>🔊 Écouter</button>
            <button id="downloadTxt" class="btn btn-warning" disabled>⬇️ Télécharger en TXT</button>
            <button id="downloadPdf" class="btn btn-danger" disabled>📄 Télécharger en PDF</button>
            <button id="summarizeText" class="btn btn-primary" disabled>✂️ Résumer</button>
        </div>

        <h2 class="mt-4">Résultat :</h2>
        <div id="result" class="result-box">Aucun texte traduit pour l’instant...</div>
    </div>

    <script>

        $(document).ready(function() {

            $('#uploadForm').submit(async function(event) {

                event.preventDefault();

                let formData = new FormData(this);

                Swal.fire({ title: 'Traduction en cours...', didOpen: () => { Swal.showLoading(); }});



                let response = await fetch('/upload/', { method: 'POST', body: formData });

                let result = await response.json();

                Swal.close();

                if (result.translated_text) {

                    $('#result').html(`<b>✨ Traduction :</b><br>${result.translated_text}`);

                    $('#copyText, #speakText, #downloadTxt, #downloadPdf, #summarizeText').prop("disabled", false);

                } else {

                    $('#result').html(`❌ Erreur: ${result.detail}`);

                }

            });



            $('#speakText').click(function() {

                let text = $('#result').text().trim();

                if (!text) return;

                let langMap = { "Francais": "fr-FR", "Anglais": "en-US", "Arabe": "ar-SA", "Espagnol": "es-ES" };

                let lang = $('#tgt_lang').val();

                let utterance = new SpeechSynthesisUtterance(text);

                utterance.lang = langMap[lang] || "fr-FR";

                utterance.rate = 1;

                utterance.pitch = 1;

                utterance.volume = 1;

                speechSynthesis.speak(utterance);

            });



            $('#summarizeText').click(async function() {

                let text = $('#result').text().trim();

                if (!text) return;

                Swal.fire({ title: 'Résumé en cours...', didOpen: () => { Swal.showLoading(); }});

                

                let response = await fetch('/summarize/', {

                    method: 'POST',

                    headers: { 'Content-Type': 'application/json' },

                    body: JSON.stringify({ text: text })

                });

                let result = await response.json();

                Swal.close();

                if (result.summary) {

                    Swal.fire("Résumé", result.summary, "info");

                } else {

                    Swal.fire("Erreur", "Impossible de résumer le texte.", "error");

                }

            });

        });

    </script>
</body>
</html>