tagny commited on
Commit
8a69289
·
1 Parent(s): 421f2a2

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Server
2
+
3
+ Hugging face spaces needs an app.py file to build the space. So the name of the python file has to be app.py
4
+
5
+ Usage: python app.py
6
+ """
7
+
8
+ import json
9
+ import gradio as gr
10
+ from textblob import TextBlob
11
+
12
+
13
+ def sentiment_analysis(text: str) -> str:
14
+ """
15
+ Analyze the sentiment of the given text.
16
+
17
+ Args:
18
+ text (str): The text to analyze
19
+
20
+ Returns:
21
+ str: A JSON string containing polarity, subjectivity, and assessment
22
+ """
23
+ blob = TextBlob(text)
24
+ sentiment = blob.sentiment
25
+
26
+ result = {
27
+ "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
28
+ "subjectivity": round(
29
+ sentiment.subjectivity, 2
30
+ ), # 0 (objective) to 1 (subjective)
31
+ "assessment": (
32
+ "positive"
33
+ if sentiment.polarity > 0
34
+ else "negative" if sentiment.polarity < 0 else "neutral"
35
+ ),
36
+ }
37
+
38
+ return json.dumps(result)
39
+
40
+
41
+ # Create the Gradio interface
42
+ demo = gr.Interface(
43
+ fn=sentiment_analysis,
44
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
45
+ outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
46
+ title="Text Sentiment Analysis",
47
+ description="Analyze the sentiment of text using TextBlob",
48
+ )
49
+
50
+ # Launch the interface and MCP server
51
+ if __name__ == "__main__":
52
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]==5.38.0
2
+ textblob==0.19.0