Spaces:
Running
Running
Download index.html from AnaDrivia/testeProfessor2: direct link, hf CLI and curl.
- Browser
- Download file 4.7 kB
-
https://huggingface.co/spaces/AnaDrivia/testeProfessor2/resolve/main/index.html
- Command line
-
hf download hf://spaces/AnaDrivia/testeProfessor2/index.html
-
curl -L -o index.html https://huggingface.co/spaces/AnaDrivia/testeProfessor2/resolve/main/index.html
4.7 kB
| <html lang="pt-BR"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" | |
| content="width=device-width, initial-scale=1.0"> | |
| <title>Análise de Sentimentos</title> | |
| <style> | |
| body { | |
| font-family: Arial, sans-serif; | |
| background: #f2f5f3; | |
| margin: 0; | |
| padding: 40px; | |
| } | |
| .container { | |
| max-width: 700px; | |
| margin: auto; | |
| background: white; | |
| padding: 30px; | |
| border-radius: 12px; | |
| box-shadow: 0 4px 15px rgba(0,0,0,0.1); | |
| } | |
| h1 { | |
| text-align: center; | |
| color: #1f7a4d; | |
| } | |
| textarea { | |
| width: 100%; | |
| height: 120px; | |
| padding: 12px; | |
| font-size: 16px; | |
| box-sizing: border-box; | |
| border: 1px solid #ccc; | |
| border-radius: 6px; | |
| resize: vertical; | |
| } | |
| button { | |
| width: 100%; | |
| margin-top: 15px; | |
| padding: 14px; | |
| border: none; | |
| border-radius: 6px; | |
| background: #1f7a4d; | |
| color: white; | |
| font-size: 16px; | |
| cursor: pointer; | |
| } | |
| button:hover { | |
| background: #155c39; | |
| } | |
| button:disabled { | |
| background: #999; | |
| cursor: wait; | |
| } | |
| #resultado { | |
| margin-top: 25px; | |
| padding: 20px; | |
| background: #f0f0f0; | |
| border-radius: 8px; | |
| text-align: center; | |
| font-size: 20px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <h1>🔎 Análise de Sentimentos</h1> | |
| <p> | |
| Digite uma frase em inglês para analisar | |
| o sentimento utilizando um modelo | |
| de Inteligência Artificial. | |
| </p> | |
| <textarea | |
| id="texto" | |
| placeholder="Ex.: I really loved this product!"> | |
| </textarea> | |
| <button | |
| id="botao" | |
| onclick="analisarSentimento()"> | |
| Analisar sentimento | |
| </button> | |
| <div id="resultado"> | |
| Carregando modelo... | |
| </div> | |
| </div> | |
| <script type="module"> | |
| import { | |
| pipeline | |
| } from | |
| "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.2"; | |
| // ====================================== | |
| // MODELO | |
| // ====================================== | |
| const classificador = | |
| await pipeline( | |
| "sentiment-analysis", | |
| "Xenova/distilbert-base-uncased-finetuned-sst-2-english" | |
| ); | |
| // ====================================== | |
| // MODELO CARREGADO | |
| // ====================================== | |
| document.getElementById("resultado") | |
| .innerHTML = | |
| "Modelo carregado. Digite um texto!"; | |
| // ====================================== | |
| // FUNÇÃO DE ANÁLISE | |
| // ====================================== | |
| window.analisarSentimento = | |
| async function() { | |
| const texto = | |
| document | |
| .getElementById("texto") | |
| .value | |
| .trim(); | |
| if (texto === "") { | |
| alert("Digite um texto."); | |
| return; | |
| } | |
| const botao = | |
| document.getElementById("botao"); | |
| const resultado = | |
| document.getElementById("resultado"); | |
| botao.disabled = true; | |
| resultado.innerHTML = | |
| "⏳ Analisando..."; | |
| try { | |
| // ================================== | |
| // INFERÊNCIA | |
| // ================================== | |
| const resposta = | |
| await classificador(texto); | |
| console.log(resposta); | |
| // ================================== | |
| // RESULTADO | |
| // ================================== | |
| const analise = | |
| resposta[0]; | |
| const sentimento = | |
| analise.label; | |
| const confianca = | |
| analise.score; | |
| let icone; | |
| if (sentimento === "POSITIVE") { | |
| icone = "😊"; | |
| } else { | |
| icone = "😞"; | |
| } | |
| resultado.innerHTML = ` | |
| ${icone} | |
| <strong>${sentimento}</strong> | |
| <br><br> | |
| Confiança: | |
| ${(confianca * 100).toFixed(2)}% | |
| `; | |
| } | |
| catch (erro) { | |
| console.error(erro); | |
| resultado.innerHTML = | |
| "❌ Erro ao executar o modelo."; | |
| } | |
| finally { | |
| botao.disabled = false; | |
| } | |
| }; | |
| </script> | |
| </body> | |
| </html> |