Spaces:
Sleeping
Sleeping
George Sergia
commited on
Commit
·
0eb21a1
1
Parent(s):
42810c4
Add files to main branch
Browse files- app.py +33 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
def analyze_sentiment(text) -> dict:
|
5 |
+
"""
|
6 |
+
Analyze the sentiment of the input text.
|
7 |
+
|
8 |
+
Args:
|
9 |
+
text (str): The input text to analyze.
|
10 |
+
|
11 |
+
Returns:
|
12 |
+
dict: A dictionary containing the polarity, subjectivity, and assessment of the text.
|
13 |
+
|
14 |
+
"""
|
15 |
+
blob = TextBlob(text)
|
16 |
+
sentiment = blob.sentiment
|
17 |
+
|
18 |
+
return {
|
19 |
+
f"polarity: {round(sentiment.polarity, 2)}",
|
20 |
+
f"subjectivity: {round(sentiment.subjectivity, 2)}",
|
21 |
+
f"assessment: {'positive' if sentiment.polarity > 0 else 'negative' if sentiment.polarity < 0 else 'neutral'}"
|
22 |
+
}
|
23 |
+
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=analyze_sentiment,
|
26 |
+
inputs=gr.Textbox(label="Input Text", placeholder="Enter text to analyze sentiment..."),
|
27 |
+
outputs=gr.JSON(),
|
28 |
+
title="Sentiment Analysis with TextBlob",
|
29 |
+
description="This app analyzes the sentiment of the input text using TextBlob and returns the polarity, subjectivity, and assessment.",
|
30 |
+
)
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
textblob
|