Goodnight7 commited on
Commit
a263911
Β·
verified Β·
1 Parent(s): fb75b78

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +12 -12
  2. app.py +40 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,12 +1,12 @@
1
- ---
2
- title: Mcp Sentiment
3
- emoji: πŸ“š
4
- colorFrom: green
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 5.38.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ---
2
+ title: Mcp Sentiment
3
+ emoji: πŸ“š
4
+ colorFrom: green
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 5.38.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from textblob import TextBlob
4
+
5
+
6
+
7
+ def sentiment_analysis(text : str ) -> str:
8
+ """
9
+ Analyze the sentiment of the given text.
10
+
11
+ Args:
12
+ text (str): The text to analyze
13
+
14
+ Returns:
15
+ str: A JSON string containing polarity, subjectivity, and assessment
16
+ """
17
+
18
+ blob = TextBlob(text)
19
+ sentiment = blob.sentiment
20
+
21
+ result = {
22
+ "polarity": round(sentiment.polarity, 2), # Polarity ranges from -1 (negative) to 1 (positive),
23
+ "subjectivity": round(sentiment.subjectivity, 2) ,
24
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
25
+
26
+ }
27
+ return json.dumps(result)
28
+
29
+
30
+ demo = gr.Interface(
31
+ fn = sentiment_analysis,
32
+ inputs = gr.Textbox(label="Enter text for sentiment analysis", placeholder="Type here..."),
33
+ outputs = gr.Textbox(),
34
+ title = "Sentiment Analysis with TextBlob",
35
+ description = "This app uses TextBlob to perform sentiment analysis on the input text. It returns the polarity, subjectivity, and overall assessment of the sentiment.",
36
+ )
37
+
38
+
39
+ if __name__ == "__main__":
40
+ demo.launch(mcp_server= True )
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio[mcp]
2
+ textblob
3
+
4
+