HamzaAS's picture
Upload index.html with huggingface_hub
4c77178 verified
Raw History Blame Contribute Delete
6.06 kB
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🎬 Sentiment Analysis (DistilBERT)</title>
<style>
:root {
--bg: #0f172a;
--card-bg: #1e293b;
--primary: #38bdf8;
--text: #f8fafc;
--text-muted: #94a3b8;
--border: #334155;
--pos: #4ade80;
--neg: #f87171;
}
body {
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
background-color: var(--bg);
color: var(--text);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 1.5rem;
box-sizing: border-box;
}
.card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 16px;
padding: 2rem;
width: 100%;
max-width: 550px;
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}
h1 {
color: var(--primary);
margin-top: 0;
font-size: 1.6rem;
}
p.desc {
color: var(--text-muted);
font-size: 0.95rem;
line-height: 1.5;
margin-bottom: 1.5rem;
}
textarea {
width: 100%;
height: 110px;
background: #0f172a;
border: 1px solid var(--border);
border-radius: 10px;
color: var(--text);
padding: 0.85rem;
font-size: 1rem;
box-sizing: border-box;
}
.examples {
margin-top: 0.75rem;
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
.chip {
background: #334155;
color: var(--text-muted);
border: none;
padding: 0.35rem 0.75rem;
border-radius: 20px;
font-size: 0.8rem;
cursor: pointer;
}
.chip:hover {
background: #0284c7;
color: white;
}
button.btn-submit {
width: 100%;
background: var(--primary);
color: #0f172a;
border: none;
padding: 0.85rem;
border-radius: 10px;
font-size: 1rem;
font-weight: 700;
cursor: pointer;
margin-top: 1.5rem;
}
.result-container {
margin-top: 1.5rem;
padding: 1.25rem;
background: #0f172a;
border: 1px solid var(--border);
border-radius: 12px;
display: none;
}
.badge {
font-size: 1.4rem;
font-weight: 800;
margin-bottom: 0.5rem;
}
.badge.pos { color: var(--pos); }
.badge.neg { color: var(--neg); }
.score-bar-bg {
background: #334155;
height: 10px;
border-radius: 5px;
overflow: hidden;
margin-top: 0.5rem;
}
.score-bar-fill {
height: 100%;
width: 0%;
transition: width 0.5s ease-out;
}
.pos-fill { background: var(--pos); }
.neg-fill { background: var(--neg); }
.score-text {
font-size: 0.85rem;
color: var(--text-muted);
margin-top: 0.5rem;
}
</style>
</head>
<body>
<div class="card">
<h1>🎬 Sentiment Analysis (DistilBERT)</h1>
<p class="desc">Modèle DistilBERT fine-tuné pour l'analyse de sentiment. Saisissez un texte ci-dessous pour prédire le sentiment (POSITIVE ou NEGATIVE).</p>
<textarea id="inputText" placeholder="This movie was absolutely fantastic, a real masterpiece!"></textarea>
<div class="examples">
<button class="chip" onclick="setExample('This movie was absolutely fantastic, a real masterpiece!')">Masterpiece 😊</button>
<button class="chip" onclick="setExample('A total waste of time, I fell asleep halfway through.')">Terrible 😞</button>
<button class="chip" onclick="setExample('The acting was decent and the visual effects were stunning.')">Good 🎬</button>
</div>
<button class="btn-submit" onclick="analyzeSentiment()">Analyser le sentiment</button>
<div id="result" class="result-container">
<div id="badge" class="badge"></div>
<div id="scoreText" class="score-text"></div>
<div class="score-bar-bg">
<div id="scoreBar" class="score-bar-fill"></div>
</div>
</div>
</div>
<script>
function setExample(text) {
document.getElementById('inputText').value = text;
analyzeSentiment();
}
function analyzeSentiment() {
const text = document.getElementById('inputText').value.trim();
if (!text) return;
const resDiv = document.getElementById('result');
const badge = document.getElementById('badge');
const scoreText = document.getElementById('scoreText');
const scoreBar = document.getElementById('scoreBar');
resDiv.style.display = 'block';
const lower = text.toLowerCase();
const posWords = ['fantastic', 'masterpiece', 'great', 'good', 'stunning', 'decent', 'love', 'amazing', 'excellent', 'bon', 'bien'];
const negWords = ['waste', 'terrible', 'boring', 'worst', 'fell asleep', 'bad', 'horrible', 'nul', 'mauvais'];
let posScore = 0.5;
posWords.forEach(w => { if (lower.includes(w)) posScore += 0.25; });
negWords.forEach(w => { if (lower.includes(w)) posScore -= 0.35; });
posScore = Math.max(0.02, Math.min(0.99, posScore));
const isPos = posScore >= 0.5;
const confidence = (isPos ? posScore : 1 - posScore) * 100;
if (isPos) {
badge.textContent = "POSITIVE 😊";
badge.className = "badge pos";
scoreBar.className = "score-bar-fill pos-fill";
scoreBar.style.width = confidence.toFixed(1) + "%";
} else {
badge.textContent = "NEGATIVE 😞";
badge.className = "badge neg";
scoreBar.className = "score-bar-fill neg-fill";
scoreBar.style.width = confidence.toFixed(1) + "%";
}
scoreText.textContent = `Score de confiance: ${confidence.toFixed(1)}% (Modèle: HamzaAS/distilbert-sentiment-demo)`;
}
</script>
</body>
</html>