AnaDrivia commited on
Commit
9fdca30
·
verified ·
1 Parent(s): 5d6492f

Update index.html

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