File size: 4,821 Bytes
6de4c8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Document Translation Service</title>
            <style>
                body {
                    font-family: Arial, sans-serif;
                    background-color: #f4f4f4;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    height: 100vh;
                    margin: 0;
                }
                .container {
                    background: white;
                    padding: 2rem;
                    border-radius: 8px;
                    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
                    width: 100%;
                    max-width: 500px;
                }
                h1 {
                    font-size: 1.8rem;
                    margin-bottom: 1rem;
                    text-align: center;
                    color: #333;
                }
                label {
                    display: block;
                    margin-bottom: 0.5rem;
                    font-weight: bold;
                }
                input, select, button {
                    width: 100%;
                    padding: 0.75rem;
                    margin-bottom: 1rem;
                    border: 1px solid #ddd;
                    border-radius: 4px;
                }
                button {
                    background-color: #4caf50;
                    color: white;
                    font-size: 1rem;
                    cursor: pointer;
                    border: none;
                }
                button:hover {
                    background-color: #45a049;
                }
                #result {
                    background: #f4f4f4;
                    padding: 1rem;
                    border: 1px solid #ddd;
                    border-radius: 4px;
                    white-space: pre-wrap;
                    min-height: 100px;
                }
                .error {
                    color: red;
                    font-weight: bold;
                }
            </style>
        </head>
        <body>
            <div class="container">
                <h1>Document Translator</h1>
                <form id="uploadForm" enctype="multipart/form-data">
                    <label for="file">Choose a file that you (TXT, PDF, DOCX, PPTX, XLSX):</label>
                    <input type="file" id="file" name="file" accept=".txt,.pdf,.docx,.pptx,.xlsx" required>
                    <label for="src_lang">Source Language:</label>
                    <select id="src_lang" name="src_lang">
                        <option>Anglais</option>
                        <option>Fran�ais</option>
                        <option>Arabe</option>
                        <option>Espagnol</option>
                        <option>Allemand</option>
                        <option>Italien</option>
                        <option>Portugais</option>
                        <option>N�erlandais</option>
                    </select>
                    <label for="tgt_lang">Target Language:</label>
                    <select id="tgt_lang" name="tgt_lang">
                        <option>Anglais</option>
                        <option>Fran�ais</option>
                        <option>Arabe</option>
                        <option>Espagnol</option>
                        <option>Allemand</option>
                        <option>Italien</option>
                        <option>Portugais</option>
                        <option>N�erlandais</option>
                    </select>
                    <button type="submit">Translate</button>
                </form>
                <h2>Translation Result:</h2>
                <pre id="result"></pre>
            </div>
            <script>
                document.getElementById('uploadForm').onsubmit = async function(event) {
                    event.preventDefault();
                    const formData = new FormData(this);
                    const response = await fetch('/upload/', {
                        method: 'POST',
                        body: formData
                    });
                    const result = await response.json();
                    if (result.translated_text) {
                        document.getElementById('result').textContent = result.translated_text;
                    } else {
                        document.getElementById('result').textContent = 'Error: ' + result.detail;
                        document.getElementById('result').classList.add('error');
                    }
                }
            </script>
        </body>
        </html>