a7madmostafa commited on
Commit
a5207b2
·
verified ·
1 Parent(s): 3a43199

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load model
5
+ pipe = pipeline(
6
+ "text-classification",
7
+ model="distilbert/distilbert-base-uncased-finetuned-sst-2-english"
8
+ )
9
+
10
+ # Inference function
11
+ def classify_text(text):
12
+ if not text.strip():
13
+ return "Please enter some text."
14
+
15
+ result = pipe(text)[0]
16
+
17
+ label = result["label"]
18
+ score = round(result["score"], 4)
19
+
20
+ return f"Sentiment: {label}\nConfidence: {score}"
21
+
22
+ # Gradio UI
23
+ app = gr.Interface(
24
+ fn=classify_text,
25
+ inputs=gr.Textbox(
26
+ lines=4,
27
+ placeholder="Type a sentence to analyze sentiment..."
28
+ ),
29
+ outputs=gr.Textbox(label="Result"),
30
+ title="Sentiment Analysis App",
31
+ description="Powered by DistilBERT (SST-2)\nClassifies text as POSITIVE or NEGATIVE."
32
+ )
33
+
34
+ # Run app
35
+ app.launch()