afkdark commited on
Commit
476068c
·
verified ·
1 Parent(s): 34cacad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load Sentiment Analysis model
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ def analyze_sentiment(text):
8
+ result = sentiment_pipeline(text)[0]
9
+ return f"Sentiment: {result['label']} (Confidence: {result['score']:.2f})"
10
+
11
+ # Create Gradio Interface
12
+ iface = gr.Interface(
13
+ fn=analyze_sentiment,
14
+ inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
15
+ outputs="text",
16
+ title="Sentiment Analysis API",
17
+ description="Enter a sentence, and the model will predict if it's POSITIVE or NEGATIVE."
18
+ )
19
+
20
+ # Launch the Gradio app
21
+ iface.launch()