Deshnni04 commited on
Commit
d668e74
·
verified ·
1 Parent(s): 427533b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from textblob import TextBlob
3
+
4
+ def analyze_sentiment(text):
5
+ if not text.strip():
6
+ return "Please enter some text."
7
+
8
+ analysis = TextBlob(text)
9
+ polarity = analysis.sentiment.polarity
10
+ if polarity > 0:
11
+ return "Positive"
12
+ elif polarity < 0:
13
+ return "Negative"
14
+ else:
15
+ return "Neutral"
16
+
17
+ description_text = (
18
+ "Enter a sentence, and the model will predict if it's POSITIVE, "
19
+ "NEGATIVE, or NEUTRAL."
20
+ )
21
+
22
+ # Gradio Interface
23
+ interface = gr.Interface(
24
+ fn=analyze_sentiment,
25
+ inputs="text",
26
+ outputs="text",
27
+ title="Sentiment Analysis API",
28
+ description=description_text,
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ interface.launch()