SurAyush commited on
Commit
0cefc66
·
1 Parent(s): 12d15bf
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging face spaces needs an app.py file to build the space
2
+ # Hosted on https://huggingface.co/spaces/SurAyush/Sentiment-Ananlysis (git origin)
3
+
4
+ import gradio as gr
5
+ import json
6
+ from textblob import TextBlob
7
+
8
+ # gradio function (proper docstring)
9
+ def analyze_sentiment(text: str) -> dict:
10
+ """
11
+ Analyze the sentiment of the input text.
12
+ Args:
13
+ text (str): The input text to analyze.
14
+ Returns:
15
+ str: A JSON string containing polarity, subjectivity, and assessment
16
+ """
17
+
18
+ blob = TextBlob(text)
19
+ sentiment = blob.sentiment
20
+ result = {
21
+ "polarity": round(sentiment.polarity,2),
22
+ "subjectivity": round(sentiment.subjectivity,2),
23
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
24
+ }
25
+
26
+ return json.dumps(result)
27
+
28
+
29
+ demo = gr.Interface(
30
+ fn = analyze_sentiment,
31
+ inputs = gr.Textbox(label="Input Text", placeholder="Enter text to analyze sentiment..."),
32
+ outputs = gr.JSON(label="Sentiment Analysis Result"),
33
+ title="Text Sentiment Analysis",
34
+ description="Analyze the sentiment of text using TextBlob"
35
+ )
36
+
37
+ if __name__ == "__main__":
38
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ textblob