aristidescc commited on
Commit
ecc5e14
·
1 Parent(s): 1edcc9b

Adding gradio app

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +31 -0
  3. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .venv
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from textblob import TextBlob
4
+
5
+ def sentiment_analysis(text):
6
+ """
7
+ Perform sentiment analysis on the input text.
8
+ Args:
9
+ text (str): The input text to analyze.
10
+ Returns:
11
+ str: A JSON string containing the sentiment analysis results: polarity, subjectivity, and assessment.
12
+ """
13
+ blob = TextBlob(text)
14
+ sentiment = blob.sentiment
15
+ return {
16
+ "polarity": round(sentiment.polarity, 2),
17
+ "subjectivity": round(sentiment.subjectivity, 2),
18
+ "assessment": "Positive" if sentiment.polarity > 0 else "Negative" if sentiment.polarity < 0 else "Neutral"
19
+ }
20
+
21
+ demo = gr.Interface(
22
+ fn=sentiment_analysis,
23
+ inputs=gr.Textbox(label="Input Text", placeholder="Enter text to analyze..."),
24
+ outputs=gr.Textbox(label="Sentiment Analysis Result"),
25
+ title="Text Sentiment Analysis",
26
+ description="This application performs sentiment analysis on the input text using TextBlob. It returns the polarity, subjectivity, and an assessment of the sentiment."
27
+ )
28
+
29
+ if __name__ == "__main__":
30
+ demo.launch(mcp_server=True)
31
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ textblob