Download index.html from AnaDrivia/teste50: direct link, hf CLI and curl.
- Browser
- Download file 5.77 kB
-
https://huggingface.co/spaces/AnaDrivia/teste50/resolve/main/index.html
- Command line
-
hf download hf://spaces/AnaDrivia/teste50/index.html
-
curl -L -o index.html https://huggingface.co/spaces/AnaDrivia/teste50/resolve/main/index.html
5.77 kB
| <html lang="pt-BR"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Gerador de Legendas de Imagens</title> | |
| <style> | |
| body { | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| background: linear-gradient(135deg, #fff0f3 0%, #f3e5f5 100%); | |
| margin: 0; | |
| padding: 40px 20px; | |
| color: #333; | |
| min-height: 100vh; | |
| } | |
| .container { | |
| max-width: 700px; | |
| margin: auto; | |
| background: #ffffff; | |
| padding: 30px; | |
| border-radius: 12px; | |
| box-shadow: 0 4px 20px rgba(106, 27, 154, 0.15); | |
| border-top: 6px solid #8e24aa; | |
| } | |
| h1 { | |
| text-align: center; | |
| color: #8e24aa; | |
| margin-top: 0; | |
| } | |
| p.description { | |
| text-align: center; | |
| color: #666; | |
| margin-bottom: 25px; | |
| } | |
| .form-group { | |
| margin-bottom: 20px; | |
| } | |
| label { | |
| display: block; | |
| font-weight: bold; | |
| margin-bottom: 8px; | |
| color: #8e24aa; /* Roxo */ | |
| } | |
| input[type="file"] { | |
| width: 100%; | |
| padding: 10px; | |
| box-sizing: border-box; | |
| border: 2px dashed #ce93d8; | |
| border-radius: 6px; | |
| background: #fdfbfd; | |
| cursor: pointer; | |
| color: #555; | |
| } | |
| .preview-container { | |
| text-align: center; | |
| margin-top: 15px; | |
| } | |
| #preview { | |
| max-width: 100%; | |
| max-height: 280px; | |
| border-radius: 8px; | |
| display: none; | |
| box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); | |
| margin-top: 10px; | |
| border: 2px solid #f3e5f5; | |
| } | |
| button { | |
| width: 100%; | |
| margin-top: 15px; | |
| padding: 14px; | |
| border: none; | |
| border-radius: 6px; | |
| /* Botão Vermelho */ | |
| background: #e53935; | |
| color: white; | |
| font-size: 16px; | |
| font-weight: bold; | |
| cursor: pointer; | |
| transition: background 0.3s, transform 0.1s; | |
| } | |
| button:hover { | |
| background: #b71c1c; | |
| } | |
| button:active { | |
| transform: scale(0.98); | |
| } | |
| button:disabled { | |
| background: #e0e0e0; | |
| color: #999; | |
| cursor: wait; | |
| transform: none; | |
| } | |
| #status { | |
| margin-top: 25px; | |
| padding: 15px; | |
| background: #f3e5f5; | |
| border-radius: 8px; | |
| text-align: center; | |
| font-size: 16px; | |
| color: #6a1b9a; | |
| font-weight: 500; | |
| } | |
| .resultado-box { | |
| margin-top: 15px; | |
| padding: 15px; | |
| background: #fff8f8; | |
| border-left: 5px solid #e53935; | |
| border-radius: 6px; | |
| } | |
| .resultado-title { | |
| font-weight: bold; | |
| color: #d32f2f; | |
| margin-bottom: 5px; | |
| font-size: 14px; | |
| text-transform: uppercase; | |
| letter-spacing: 0.5px; | |
| } | |
| .resultado-text { | |
| font-size: 16px; | |
| color: #222; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>Gerador de Legendas</h1> | |
| <p class="description"> | |
| Envie uma imagem para gerar uma legenda automática com IA! | |
| </p> | |
| <!-- Upload da Imagem --> | |
| <div class="form-group"> | |
| <label for="imagem">Selecione uma imagem:</label> | |
| <input type="file" id="imagem" accept="image/*"> | |
| <div class="preview-container"> | |
| <img id="preview" alt="Pré-visualização da imagem"> | |
| </div> | |
| </div> | |
| <button id="botao" onclick="gerarLegenda()">Gerar legenda</button> | |
| <div id="status">Carregando modelo... Aguarde.</div> | |
| <div id="resultados" style="display: none;"> | |
| <div class="resultado-box"> | |
| <div class="resultado-title">Legenda Gerada</div> | |
| <div class="resultado-text" id="resLegenda">-</div> | |
| </div> | |
| </div> | |
| </div> | |
| <script type="module"> | |
| import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.2"; | |
| let captioner = null; | |
| const inputImagem = document.getElementById("imagem"); | |
| const imgPreview = document.getElementById("preview"); | |
| const statusDiv = document.getElementById("status"); | |
| const botao = document.getElementById("botao"); | |
| // Exibe a pré-visualização da imagem selecionada | |
| inputImagem.addEventListener("change", (e) => { | |
| const file = e.target.files[0]; | |
| if (file) { | |
| const url = URL.createObjectURL(file); | |
| imgPreview.src = url; | |
| imgPreview.style.display = "inline-block"; | |
| } else { | |
| imgPreview.style.display = "none"; | |
| } | |
| }); | |
| try { | |
| captioner = await pipeline( | |
| "image-to-text", | |
| "Xenova/vit-gpt2-image-captioning" | |
| ); | |
| statusDiv.innerHTML = "✅ Modelo carregado. Selecione uma imagem e clique em Gerar!"; | |
| } catch (erro) { | |
| console.error(erro); | |
| statusDiv.innerHTML = "❌ Erro ao carregar o modelo."; | |
| } | |
| window.gerarLegenda = async function () { | |
| if (!captioner) { | |
| alert("O modelo ainda está sendo carregado. Por favor, aguarde."); | |
| return; | |
| } | |
| const file = inputImagem.files[0]; | |
| if (!file) { | |
| alert("Por favor, envie uma imagem antes de gerar."); | |
| return; | |
| } | |
| const imageUrl = imgPreview.src; | |
| botao.disabled = true; | |
| statusDiv.innerHTML = "⏳ Analisando a imagem..."; | |
| try { | |
| const resposta = await captioner(imageUrl, { | |
| max_new_tokens: 50 | |
| }); | |
| const legenda = resposta[0]?.generated_text || "Não foi possível gerar."; | |
| document.getElementById("resLegenda").innerText = legenda; | |
| document.getElementById("resultados").style.display = "block"; | |
| statusDiv.innerHTML = "✨ Legenda gerada com sucesso!"; | |
| } catch (erro) { | |
| console.error(erro); | |
| statusDiv.innerHTML = "❌ Erro ao processar a imagem."; | |
| } finally { | |
| botao.disabled = false; | |
| } | |
| }; | |
| </script> | |
| </body> | |
| </html> |