Spaces:
Sleeping
Sleeping
Mustafa Nab
commited on
Commit
·
5c94d18
1
Parent(s):
38202f0
Add application files
Browse files- app.py +39 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
|
5 |
+
def sentiment_analysis(text: str) -> dict:
|
6 |
+
"""
|
7 |
+
Analyze the sentiment of a given text.
|
8 |
+
|
9 |
+
Args:
|
10 |
+
text (str): The input text to analyze.
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
str: The sentiment of the text, either 'Positive', 'Negative', or 'Neutral'.
|
14 |
+
"""
|
15 |
+
blob = TextBlob(text)
|
16 |
+
sentiment = blob.sentiment
|
17 |
+
return {
|
18 |
+
"polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
|
19 |
+
"subjectivity": round(
|
20 |
+
sentiment.subjectivity, 2
|
21 |
+
), # 0 (objective) to 1 (subjective)
|
22 |
+
"assessment": (
|
23 |
+
"Positive"
|
24 |
+
if sentiment.polarity > 0
|
25 |
+
else "Negative" if sentiment.polarity < 0 else "Neutral"
|
26 |
+
),
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
demo = gr.Interface(
|
31 |
+
fn=sentiment_analysis,
|
32 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze sentiment..."),
|
33 |
+
outputs=gr.JSON(),
|
34 |
+
title="Sentiment Analysis",
|
35 |
+
description="Analyze the sentiment of a given text using TextBlob.",
|
36 |
+
)
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
textblob
|