|
<!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>
|
|
|