Spaces:
Runtime error
Runtime error
abuhijleh
commited on
Commit
·
a07549e
0
Parent(s):
Initial commit: Sentiment Analysis App with clean history
Browse files- .gitignore +24 -0
- README.md +13 -0
- app.py +34 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Python virtual environment
|
2 |
+
venv/
|
3 |
+
|
4 |
+
# Python bytecode
|
5 |
+
__pycache__/
|
6 |
+
*.py[cod]
|
7 |
+
*$py.class
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
dist/
|
11 |
+
build/
|
12 |
+
*.egg-info/
|
13 |
+
|
14 |
+
# IDE specific files
|
15 |
+
.idea/
|
16 |
+
.vscode/
|
17 |
+
*.swp
|
18 |
+
*.swo
|
19 |
+
|
20 |
+
# Environment variables
|
21 |
+
.env
|
22 |
+
|
23 |
+
# Distribution / packaging
|
24 |
+
.DS_Store
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Text Sentiment Analysis
|
2 |
+
|
3 |
+
This is a simple sentiment analysis application built with Gradio and TextBlob. It analyzes the sentiment of input text and provides:
|
4 |
+
- Polarity score (-1 to 1, where -1 is negative and 1 is positive)
|
5 |
+
- Subjectivity score (0 to 1, where 0 is objective and 1 is subjective)
|
6 |
+
- Overall assessment (positive, negative, or neutral)
|
7 |
+
|
8 |
+
## Usage
|
9 |
+
Simply enter any text in the input box and the application will analyze its sentiment.
|
10 |
+
|
11 |
+
## Technologies Used
|
12 |
+
- Gradio for the web interface
|
13 |
+
- TextBlob for sentiment analysis
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
def sentiment_analysis(text: str) -> dict:
|
5 |
+
"""
|
6 |
+
Analyze the sentiment of the given text.
|
7 |
+
|
8 |
+
Args:
|
9 |
+
text (str): The text to analyze
|
10 |
+
|
11 |
+
Returns:
|
12 |
+
dict: A dictionary containing polarity, subjectivity, and assessment
|
13 |
+
"""
|
14 |
+
blob = TextBlob(text)
|
15 |
+
sentiment = blob.sentiment
|
16 |
+
|
17 |
+
return {
|
18 |
+
"polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
|
19 |
+
"subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
|
20 |
+
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
21 |
+
}
|
22 |
+
|
23 |
+
# Create the Gradio interface
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=sentiment_analysis,
|
26 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
27 |
+
outputs=gr.JSON(),
|
28 |
+
title="Text Sentiment Analysis",
|
29 |
+
description="Analyze the sentiment of text using TextBlob"
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the interface and MCP server
|
33 |
+
if __name__ == "__main__":
|
34 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
textblob
|