Spaces:
Running
Running
Download index.html from Adrien653/sentiment-analysis: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/spaces/Adrien653/sentiment-analysis/resolve/main/index.html
- Command line
-
hf download hf://spaces/Adrien653/sentiment-analysis/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Adrien653/sentiment-analysis/resolve/main/index.html
2.55 kB
| <html lang="fr"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Sentiment Analysis (DistilBERT)</title> | |
| <style> | |
| body { | |
| font-family: sans-serif; | |
| max-width: 640px; | |
| margin: 40px auto; | |
| padding: 0 16px; | |
| } | |
| textarea { | |
| width: 100%; | |
| box-sizing: border-box; | |
| } | |
| .bar { | |
| background: #eee; | |
| border-radius: 4px; | |
| margin: 6px 0; | |
| } | |
| .fill { | |
| background: #3f51b5; | |
| color: white; | |
| padding: 4px 8px; | |
| border-radius: 4px; | |
| white-space: nowrap; | |
| } | |
| button { | |
| margin: 10px 4px 10px 0; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Sentiment Analysis (DistilBERT)</h1> | |
| <p> | |
| DistilBERT fine-tuné sur le dataset | |
| <code>rotten_tomatoes</code>. | |
| Le modèle est exécuté directement dans le navigateur | |
| avec ONNX et Transformers.js. | |
| </p> | |
| <textarea | |
| id="text" | |
| rows="4" | |
| placeholder="Enter a movie review..."> | |
| This movie was absolutely fantastic! | |
| </textarea> | |
| <br> | |
| <button id="btn" disabled> | |
| Analyser | |
| </button> | |
| <button id="positive" type="button"> | |
| Exemple positif | |
| </button> | |
| <button id="negative" type="button"> | |
| Exemple négatif | |
| </button> | |
| <div id="result"> | |
| Chargement du modèle... | |
| </div> | |
| <script type="module"> | |
| import { pipeline } | |
| from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.8.1"; | |
| const result = document.getElementById("result"); | |
| const btn = document.getElementById("btn"); | |
| const text = document.getElementById("text"); | |
| document.getElementById("positive").onclick = () => { | |
| text.value = | |
| "This movie was absolutely fantastic, a real masterpiece!"; | |
| }; | |
| document.getElementById("negative").onclick = () => { | |
| text.value = | |
| "A total waste of time, I fell asleep halfway through."; | |
| }; | |
| try { | |
| const classifier = await pipeline( | |
| "text-classification", | |
| "Adrien653/distilbert-rotten-tomatoes", | |
| { dtype: "fp32" } | |
| ); | |
| result.textContent = | |
| "Modèle chargé. Entrez un texte."; | |
| btn.disabled = false; | |
| btn.onclick = async () => { | |
| result.textContent = | |
| "Analyse en cours..."; | |
| const predictions = | |
| await classifier(text.value, { top_k: null }); | |
| result.innerHTML = predictions.map(p => | |
| `<div class="bar"> | |
| <div class="fill" | |
| style="width:${Math.max(8, p.score * 100)}%"> | |
| ${p.label} : | |
| ${(p.score * 100).toFixed(1)} % | |
| </div> | |
| </div>` | |
| ).join(""); | |
| }; | |
| } | |
| catch (error) { | |
| console.error(error); | |
| result.textContent = | |
| "Erreur pendant le chargement : " + error.message; | |
| } | |
| </script> | |
| </body> | |
| </html> |