AdrieleM commited on
Commit
14894e1
·
verified ·
1 Parent(s): ace702b

Add App.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from textblob import TextBlob
4
+
5
+ def sentiment_anaysis(text: str) -> str:
6
+ """
7
+ Analyze the sentiment or the given text.
8
+
9
+ Args:
10
+ text (str): The text to analyze
11
+
12
+ Returns:
13
+ str: A JSON string containing polarity, subjectivity, and assessment
14
+ """
15
+ blob = TextBlob(text)
16
+ sentiment = blob.sentiment
17
+
18
+ result = {
19
+ "polarity": round(sentiment.polarity, 2),
20
+ "subjectivity": round(sentiment.subjectivity, 2),
21
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
22
+ }
23
+
24
+ return json.dumps(result)
25
+
26
+ demo = gr.Interface(
27
+ fn=sentiment_anaysis,
28
+ inputs=gr.Textbox(placeholder="Enter Text to analyze..."),
29
+ outputs=gr.Textbox(),
30
+ title="Text Sentiment Analysis",
31
+ description="Analyze the sentiment of text using TextBlob"
32
+ )
33
+
34
+ if __name__ == "__main__":
35
+ demo.launch()