arinbalyan commited on
Commit
d3d47eb
Β·
verified Β·
1 Parent(s): 95a2531

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +31 -4
  2. app.py +58 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,40 @@
1
  ---
2
  title: Sentiment Analyzer
3
- emoji: πŸš€
4
  colorFrom: indigo
5
- colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 6.19.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Sentiment Analyzer
3
+ emoji: 🎭
4
  colorFrom: indigo
5
+ colorTo: pink
6
  sdk: gradio
7
  sdk_version: 6.19.0
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # 🎭 Sentiment Analyzer
13
+
14
+ A lightweight text sentiment classifier running DistilBERT (67M params).
15
+ Type any sentence and get instant positive/negative analysis.
16
+
17
+ **Why this exists:** Small models can do real work. This runs on CPU in
18
+ milliseconds β€” no GPU needed, no queue, no waiting.
19
+
20
+ **What I learned building this:**
21
+ - Loading transformers pipelines for inference
22
+ - Building clean Gradio interfaces
23
+ - Deploying to Hugging Face Spaces
24
+
25
+ ## Usage
26
+
27
+ ```python
28
+ from transformers import pipeline
29
+
30
+ classifier = pipeline(
31
+ "sentiment-analysis",
32
+ model="distilbert-base-uncased-finetuned-sst-2-english"
33
+ )
34
+ classifier("This is great!")
35
+ # [{'label': 'POSITIVE', 'score': 0.9998}]
36
+ ```
37
+
38
+ ## Links
39
+ - **HF Profile:** [arinbalyan](https://huggingface.co/arinbalyan)
40
+ - **Training Notebook:** Coming soon (Kaggle fine-tune on custom data)
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # ponytail: single pipeline call, no wrapping class needed
5
+ classifier = pipeline(
6
+ "sentiment-analysis",
7
+ model="distilbert-base-uncased-finetuned-sst-2-english",
8
+ )
9
+
10
+ # ponytail: examples embedded, no external file
11
+ EXAMPLES = [
12
+ "This movie was absolutely incredible! Best I've seen all year.",
13
+ "Waste of time. Terrible acting, predictable plot.",
14
+ "It was okay, nothing special but not bad either.",
15
+ "The cinematography was stunning but the story fell flat.",
16
+ "I've watched it three times already. Pure masterpiece.",
17
+ ]
18
+
19
+ def analyze(text):
20
+ result = classifier(text[:512])[0] # ponytail: hard truncate, no tokenizer logic
21
+ label = result["label"]
22
+ score = result["score"]
23
+ emoji = "😊" if label == "POSITIVE" else "😞"
24
+ return {emoji: score if label == "POSITIVE" else 1 - score}
25
+
26
+ with gr.Blocks(theme=gr.themes.Soft(), title="Sentiment Analyzer") as demo:
27
+ gr.Markdown(
28
+ """
29
+ # 🎭 Sentiment Analyzer
30
+
31
+ Tiny model, big opinions. Type any text and see if it's positive or negative.
32
+
33
+ **Model:** DistilBERT fine-tuned on SST-2 (67M params, runs on CPU)
34
+ """
35
+ )
36
+ with gr.Row():
37
+ text_input = gr.Textbox(
38
+ label="Your text",
39
+ placeholder="What's on your mind?",
40
+ lines=3,
41
+ )
42
+ with gr.Row():
43
+ btn = gr.Button("Analyze", variant="primary", scale=0)
44
+ with gr.Row():
45
+ output = gr.Label(label="Sentiment", num_top_classes=2)
46
+
47
+ btn.click(fn=analyze, inputs=text_input, outputs=output)
48
+ gr.Examples(examples=EXAMPLES, inputs=text_input)
49
+
50
+ gr.Markdown(
51
+ """
52
+ ---
53
+ Built with [DistilBERT](https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english) | [arinbalyan](https://huggingface.co/arinbalyan)
54
+ """
55
+ )
56
+
57
+ if __name__ == "__main__":
58
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # ponytail: pinned to what HF Spaces already has
2
+ transformers>=4.30
3
+ torch>=2.0