ViniCarini commited on
Commit
c3560a4
·
verified ·
1 Parent(s): 3ec1bac

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +192 -19
index.html CHANGED
@@ -1,19 +1,192 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="pt-BR">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Tradutor IA com T5 (JS)</title>
7
+ <style>
8
+ :root {
9
+ --bg-color: #f4f6f9;
10
+ --card-bg: #ffffff;
11
+ --primary: #2563eb;
12
+ --primary-hover: #1d4ed8;
13
+ --text: #1f2937;
14
+ --border: #e5e7eb;
15
+ }
16
+
17
+ body {
18
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
19
+ background-color: var(--bg-color);
20
+ color: var(--text);
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ min-height: 100vh;
25
+ margin: 0;
26
+ padding: 20px;
27
+ }
28
+
29
+ .container {
30
+ background-color: var(--card-bg);
31
+ border-radius: 12px;
32
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
33
+ width: 100%;
34
+ max-width: 650px;
35
+ padding: 30px;
36
+ box-sizing: border-box;
37
+ }
38
+
39
+ h1 {
40
+ margin-top: 0;
41
+ font-size: 1.5rem;
42
+ text-align: center;
43
+ }
44
+
45
+ p.description {
46
+ text-align: center;
47
+ color: #6b7280;
48
+ font-size: 0.9rem;
49
+ margin-bottom: 24px;
50
+ }
51
+
52
+ .form-group {
53
+ margin-bottom: 20px;
54
+ }
55
+
56
+ label {
57
+ display: block;
58
+ font-weight: 600;
59
+ margin-bottom: 8px;
60
+ font-size: 0.9rem;
61
+ }
62
+
63
+ textarea {
64
+ width: 100%;
65
+ height: 120px;
66
+ padding: 12px;
67
+ border: 1px solid var(--border);
68
+ border-radius: 8px;
69
+ resize: vertical;
70
+ font-family: inherit;
71
+ font-size: 1rem;
72
+ box-sizing: border-box;
73
+ }
74
+
75
+ textarea:focus {
76
+ outline: none;
77
+ border-color: var(--primary);
78
+ }
79
+
80
+ button {
81
+ width: 100%;
82
+ background-color: var(--primary);
83
+ color: white;
84
+ border: none;
85
+ padding: 12px;
86
+ border-radius: 8px;
87
+ font-size: 1rem;
88
+ font-weight: 600;
89
+ cursor: pointer;
90
+ transition: background-color 0.2s;
91
+ }
92
+
93
+ button:hover {
94
+ background-color: var(--primary-hover);
95
+ }
96
+
97
+ button:disabled {
98
+ background-color: #9ca3af;
99
+ cursor: not-allowed;
100
+ }
101
+
102
+ .status {
103
+ margin-top: 15px;
104
+ font-size: 0.85rem;
105
+ color: #4b5563;
106
+ text-align: center;
107
+ }
108
+ </style>
109
+ </head>
110
+ <body>
111
+
112
+ <div class="container">
113
+ <h1>Tradutor IA com T5</h1>
114
+ <p class="description">Insira uma frase em inglês para gerar a tradução em alemão rodando direto no seu navegador.</p>
115
+
116
+ <div class="form-group">
117
+ <label for="inputText">Inglês:</label>
118
+ <textarea id="inputText" placeholder="Digite o texto em inglês aqui..."></textarea>
119
+ </div>
120
+
121
+ <button id="translateBtn">Carregando Modelo...</button>
122
+
123
+ <div class="form-group" style="margin-top: 20px;">
124
+ <label for="outputText">Tradução em Alemão:</label>
125
+ <textarea id="outputText" readonly placeholder="A tradução aparecerá aqui..."></textarea>
126
+ </div>
127
+
128
+ <div id="status" class="status">Baixando bibliotecas...</div>
129
+ </div>
130
+
131
+ <script type="module">
132
+ // Importa a biblioteca Transformers.js via CDN
133
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2';
134
+
135
+ const inputText = document.getElementById('inputText');
136
+ const outputText = document.getElementById('outputText');
137
+ const translateBtn = document.getElementById('translateBtn');
138
+ const statusDiv = document.getElementById('status');
139
+
140
+ let generator = null;
141
+
142
+ // Inicializa o modelo no navegador
143
+ async function initModel() {
144
+ try {
145
+ statusDiv.innerText = "Carregando modelo T5 na memória do navegador (isso pode demorar no primeiro acesso)...";
146
+ translateBtn.disabled = true;
147
+
148
+ // Carrega o pipeline text2text-generation usando o modelo ONNX
149
+ generator = await pipeline('text2text-generation', 'Xenova/t5-base');
150
+
151
+ statusDiv.innerText = "Modelo pronto!";
152
+ translateBtn.innerText = "Traduzir";
153
+ translateBtn.disabled = false;
154
+ } catch (error) {
155
+ statusDiv.innerText = "Erro ao carregar o modelo: " + error.message;
156
+ console.error(error);
157
+ }
158
+ }
159
+
160
+ // Função para traduzir o texto
161
+ async function traduzirTexto() {
162
+ const text = inputText.value.trim();
163
+ if (!text) return;
164
+
165
+ translateBtn.disabled = true;
166
+ translateBtn.innerText = "Traduzindo...";
167
+ statusDiv.innerText = "Processando entrada...";
168
+
169
+ try {
170
+ const prompt = `translate English to German: ${text}`;
171
+ const output = await generator(prompt, { max_new_tokens: 512 });
172
+
173
+ outputText.value = output[0].generated_text;
174
+ statusDiv.innerText = "Tradução concluída com sucesso!";
175
+ } catch (error) {
176
+ statusDiv.innerText = "Erro durante a tradução: " + error.message;
177
+ console.error(error);
178
+ } finally {
179
+ translateBtn.disabled = false;
180
+ translateBtn.innerText = "Traduzir";
181
+ }
182
+ }
183
+
184
+ // Event Listeners
185
+ translateBtn.addEventListener('click', traduzirTexto);
186
+
187
+ // Inicia o carregamento do modelo ao abrir a página
188
+ initModel();
189
+ </script>
190
+
191
+ </body>
192
+ </html>