profplate commited on
Commit
8038e76
Β·
verified Β·
1 Parent(s): 594b56f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py CHANGED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a sentiment analysis model (works on free CPU)
5
+ analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
6
+
7
+ def check_mood(text):
8
+ if not text or not text.strip():
9
+ return "Paste some text above first!"
10
+
11
+ result = analyzer(text)[0]
12
+ label = result["label"]
13
+ score = result["score"]
14
+
15
+ if label == "POSITIVE":
16
+ emoji = "😊" if score > 0.9 else "πŸ™‚"
17
+ else:
18
+ emoji = "😒" if score > 0.9 else "😐"
19
+
20
+ return f"{emoji} {label}\n\nConfidence: {score:.0%}"
21
+
22
+ demo = gr.Interface(
23
+ fn=check_mood,
24
+ inputs=gr.Textbox(lines=8, placeholder="Paste any text here β€” a song lyric, a diary entry, a text from a friend..."),
25
+ outputs=gr.Textbox(label="Mood Reading"),
26
+ title="Mood Meter",
27
+ description="Paste any text and this AI will tell you whether it feels POSITIVE or NEGATIVE β€” and how confident it is. Does the model agree with how YOU feel about the text?",
28
+ examples=[
29
+ ["I can't believe how lucky I am to have friends like you. Every day feels like an adventure and I wouldn't trade it for anything in the world."],
30
+ ["I don't know why I even bother anymore. Nothing I do seems to matter and nobody notices when I try my hardest."],
31
+ ["Dear future me, I hope you figured it out. I hope you're not still lying awake at 2am wondering if you made the right choice."],
32
+ ["Walking into school on the first day felt like stepping onto another planet. Everyone already knew each other and I just stood there holding my backpack straps."],
33
+ ],
34
+ )
35
+
36
+ demo.launch()