likhonhfai commited on
Commit
b032256
·
verified ·
1 Parent(s): 03ee6e8

Add app.py: Sentiment analysis Gradio interface

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a small sentiment analysis pipeline
5
+ classifier = pipeline("sentiment-analysis")
6
+
7
+ def analyze_sentiment(text):
8
+ result = classifier(text)[0]
9
+ label = result["label"]
10
+ score = result["score"]
11
+ return f"{label} ({score:.2f})"
12
+
13
+ # Create Gradio interface
14
+ iface = gr.Interface(
15
+ fn=analyze_sentiment,
16
+ inputs=gr.Textbox(lines=5, placeholder="Enter text here...", label="Input Text"),
17
+ outputs=gr.Textbox(label="Sentiment"),
18
+ title="Tiny AI Sentiment Analyzer",
19
+ description="Enter a text snippet and get its sentiment (positive/negative) using a small Hugging Face model."
20
+ )
21
+
22
+ if __name__ == "__main__":
23
+ iface.launch()