proitm commited on
Commit
1feb7fc
·
verified ·
1 Parent(s): a7680b0

Added application

Browse files
Files changed (2) hide show
  1. app.py +32 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from textblob import TextBlob
4
+
5
+ def sentiment_analysis(text: str) -> dict:
6
+ """"
7
+ Analyze sentiment for the given text.
8
+
9
+ Args:
10
+ text (str): Text to analyze.
11
+
12
+ Returns:
13
+ dict: A dictionary polarity, subjectivity and assesment.
14
+ """
15
+ blob = TextBlob(text)
16
+ sentiment = blob.sentiment
17
+ return {
18
+ "polarity": round(sentiment.polarity, 2),
19
+ "subjectivity": round(sentiment.subjectivity, 2),
20
+ "assesment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral",
21
+ }
22
+
23
+ app = gr.Interface(
24
+ fn=sentiment_analysis,
25
+ inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
26
+ outputs=gr.JSON(),
27
+ title="Text Sentiment Analysis",
28
+ description="Analyze sentiment of text using TextBlob."
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ app.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ textblob