AnaDrivia commited on
Commit
f4e3572
·
verified ·
1 Parent(s): e1f46c3

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +293 -19
index.html CHANGED
@@ -1,19 +1,293 @@
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
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Gerador de Legendas de Imagens (BLIP)</title>
8
+
9
+ <style>
10
+ body {
11
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
12
+ /* Fundo com um gradiente bem suave entre um tom claro de vermelho (rosa) e roxo */
13
+ background: linear-gradient(135deg, #fff0f3 0%, #f3e5f5 100%);
14
+ margin: 0;
15
+ padding: 40px 20px;
16
+ color: #333;
17
+ min-height: 100vh;
18
+ }
19
+
20
+ .container {
21
+ max-width: 700px;
22
+ margin: auto;
23
+ background: #ffffff;
24
+ padding: 30px;
25
+ border-radius: 12px;
26
+ box-shadow: 0 4px 20px rgba(106, 27, 154, 0.15);
27
+ /* Borda superior roxa */
28
+ border-top: 6px solid #8e24aa;
29
+ }
30
+
31
+ h1 {
32
+ text-align: center;
33
+ color: #8e24aa; /* Roxo principal */
34
+ margin-top: 0;
35
+ }
36
+
37
+ p.description {
38
+ text-align: center;
39
+ color: #666;
40
+ margin-bottom: 25px;
41
+ }
42
+
43
+ .form-group {
44
+ margin-bottom: 20px;
45
+ }
46
+
47
+ label {
48
+ display: block;
49
+ font-weight: bold;
50
+ margin-bottom: 8px;
51
+ color: #8e24aa; /* Roxo */
52
+ }
53
+
54
+ input[type="file"] {
55
+ width: 100%;
56
+ padding: 10px;
57
+ box-sizing: border-box;
58
+ border: 2px dashed #ce93d8;
59
+ border-radius: 6px;
60
+ background: #fdfbfd;
61
+ cursor: pointer;
62
+ color: #555;
63
+ }
64
+
65
+ input[type="text"] {
66
+ width: 100%;
67
+ padding: 12px;
68
+ font-size: 16px;
69
+ box-sizing: border-box;
70
+ border: 1px solid #e0e0e0;
71
+ border-radius: 6px;
72
+ outline: none;
73
+ }
74
+
75
+ input[type="text"]:focus {
76
+ border-color: #8e24aa;
77
+ }
78
+
79
+ .preview-container {
80
+ text-align: center;
81
+ margin-top: 15px;
82
+ }
83
+
84
+ #preview {
85
+ max-width: 100%;
86
+ max-height: 280px;
87
+ border-radius: 8px;
88
+ display: none;
89
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
90
+ margin-top: 10px;
91
+ border: 2px solid #f3e5f5;
92
+ }
93
+
94
+ button {
95
+ width: 100%;
96
+ margin-top: 15px;
97
+ padding: 14px;
98
+ border: none;
99
+ border-radius: 6px;
100
+ /* Botão Vermelho */
101
+ background: #e53935;
102
+ color: white;
103
+ font-size: 16px;
104
+ font-weight: bold;
105
+ cursor: pointer;
106
+ transition: background 0.3s, transform 0.1s;
107
+ }
108
+
109
+ button:hover {
110
+ background: #b71c1c; /* Vermelho mais escuro no hover */
111
+ }
112
+
113
+ button:active {
114
+ transform: scale(0.98);
115
+ }
116
+
117
+ button:disabled {
118
+ background: #e0e0e0;
119
+ color: #999;
120
+ cursor: wait;
121
+ transform: none;
122
+ }
123
+
124
+ #status {
125
+ margin-top: 25px;
126
+ padding: 15px;
127
+ background: #f3e5f5; /* Fundo roxo bem claro */
128
+ border-radius: 8px;
129
+ text-align: center;
130
+ font-size: 16px;
131
+ color: #6a1b9a; /* Texto roxo escuro */
132
+ font-weight: 500;
133
+ }
134
+
135
+ .resultado-box {
136
+ margin-top: 15px;
137
+ padding: 15px;
138
+ background: #fff8f8; /* Fundo levemente avermelhado */
139
+ border-left: 5px solid #e53935; /* Detalhe vermelho */
140
+ border-radius: 6px;
141
+ }
142
+
143
+ .resultado-title {
144
+ font-weight: bold;
145
+ color: #d32f2f; /* Título vermelho */
146
+ margin-bottom: 5px;
147
+ font-size: 14px;
148
+ text-transform: uppercase;
149
+ letter-spacing: 0.5px;
150
+ }
151
+
152
+ .resultado-text {
153
+ font-size: 16px;
154
+ color: #222;
155
+ }
156
+ </style>
157
+ </head>
158
+
159
+ <body>
160
+
161
+ <div class="container">
162
+ <h1>📷 Gerador de Legendas (BLIP)</h1>
163
+ <p class="description">
164
+ Envie uma imagem para gerar legendas automáticas. Modelo leve otimizado para Web!
165
+ </p>
166
+
167
+ <!-- Upload da Imagem -->
168
+ <div class="form-group">
169
+ <label for="imagem">1. Selecione uma imagem:</label>
170
+ <input type="file" id="imagem" accept="image/*">
171
+ <div class="preview-container">
172
+ <img id="preview" alt="Pré-visualização da imagem">
173
+ </div>
174
+ </div>
175
+
176
+ <!-- Texto de contexto inicial -->
177
+ <div class="form-group">
178
+ <label for="prompt">2. Texto inicial (Condicional):</label>
179
+ <input type="text" id="prompt" value="a photography of a" placeholder="Ex: a photography of a">
180
+ </div>
181
+
182
+ <!-- Botão de Ação -->
183
+ <button id="botao" onclick="gerarLegendas()">Gerar legendas</button>
184
+
185
+ <!-- Status do carregamento/inferência -->
186
+ <div id="status">Carregando modelo BLIP Base (Leve)... Aguarde.</div>
187
+
188
+ <!-- Resultados -->
189
+ <div id="resultados" style="display: none;">
190
+ <div class="resultado-box">
191
+ <div class="resultado-title">Resultado Condicional</div>
192
+ <div class="resultado-text" id="resCondicional">-</div>
193
+ </div>
194
+
195
+ <div class="resultado-box">
196
+ <div class="resultado-title">Resultado Incondicional</div>
197
+ <div class="resultado-text" id="resIncondicional">-</div>
198
+ </div>
199
+ </div>
200
+ </div>
201
+
202
+ <script type="module">
203
+ import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.2";
204
+
205
+ let captioner = null;
206
+
207
+ const inputImagem = document.getElementById("imagem");
208
+ const imgPreview = document.getElementById("preview");
209
+ const statusDiv = document.getElementById("status");
210
+ const botao = document.getElementById("botao");
211
+
212
+ // Exibe a pré-visualização da imagem selecionada
213
+ inputImagem.addEventListener("change", (e) => {
214
+ const file = e.target.files[0];
215
+ if (file) {
216
+ const url = URL.createObjectURL(file);
217
+ imgPreview.src = url;
218
+ imgPreview.style.display = "inline-block";
219
+ } else {
220
+ imgPreview.style.display = "none";
221
+ }
222
+ });
223
+
224
+ // ======================================
225
+ // CARREGAMENTO DO MODELO (VERSÃO BASE - LEVE)
226
+ // ======================================
227
+ try {
228
+ // Usando a versão "base" que é muito menor (~250MB quantizada)
229
+ captioner = await pipeline(
230
+ "image-to-text",
231
+ "Xenova/blip-image-captioning-base"
232
+ );
233
+
234
+ statusDiv.innerHTML = "✅ Modelo carregado. Selecione uma imagem e clique em Gerar!";
235
+ } catch (erro) {
236
+ console.error(erro);
237
+ statusDiv.innerHTML = "❌ Erro ao carregar o modelo BLIP.";
238
+ }
239
+
240
+ // ======================================
241
+ // FUNÇÃO DE GERAÇÃO DE LEGENDAS
242
+ // ======================================
243
+ window.gerarLegendas = async function () {
244
+ if (!captioner) {
245
+ alert("O modelo ainda está sendo carregado. Por favor, aguarde.");
246
+ return;
247
+ }
248
+
249
+ const file = inputImagem.files[0];
250
+ if (!file) {
251
+ alert("Por favor, envie uma imagem antes de gerar.");
252
+ return;
253
+ }
254
+
255
+ const promptText = document.getElementById("prompt").value.trim();
256
+ const imageUrl = imgPreview.src;
257
+
258
+ botao.disabled = true;
259
+ statusDiv.innerHTML = "⏳ Analisando a imagem...";
260
+
261
+ try {
262
+ // 1. Legenda Condicional
263
+ const resCond = await captioner(imageUrl, {
264
+ prompt: promptText,
265
+ max_new_tokens: 50
266
+ });
267
+
268
+ // 2. Legenda Incondicional
269
+ const resUncond = await captioner(imageUrl, {
270
+ max_new_tokens: 50
271
+ });
272
+
273
+ // Extrai as legendas geradas
274
+ const condicionalText = resCond[0]?.generated_text || "Não foi possível gerar.";
275
+ const incondicionalText = resUncond[0]?.generated_text || "Não foi possível gerar.";
276
+
277
+ document.getElementById("resCondicional").innerText = condicionalText;
278
+ document.getElementById("resIncondicional").innerText = incondicionalText;
279
+
280
+ document.getElementById("resultados").style.display = "block";
281
+ statusDiv.innerHTML = "✨ Legendas geradas com sucesso!";
282
+ } catch (erro) {
283
+ console.error(erro);
284
+ statusDiv.innerHTML = "❌ Erro ao processar a imagem.";
285
+ } finally {
286
+ botao.disabled = false;
287
+ }
288
+ };
289
+ </script>
290
+
291
+ </body>
292
+
293
+ </html>