Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- .gitignore +1 -0
- app.py +34 -0
- runtime.txt +1 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv/
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['demo', 'analyze_sentiment']
|
5 |
+
|
6 |
+
# %% app.ipynb 1
|
7 |
+
import gradio as gr
|
8 |
+
from textblob import TextBlob
|
9 |
+
|
10 |
+
# %% app.ipynb 3
|
11 |
+
def analyze_sentiment(text):
|
12 |
+
"""
|
13 |
+
Analyze the sentiment of the given text.
|
14 |
+
|
15 |
+
Args:
|
16 |
+
text (str): The text to analyze
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
dict: A dictionary containing polarity, subjectivity, and assessment
|
20 |
+
"""
|
21 |
+
blob = TextBlob(text)
|
22 |
+
sentiment = blob.sentiment
|
23 |
+
assessments = "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
24 |
+
return {"polarity": round(sentiment.polarity, 2),
|
25 |
+
"subjectivity": round(sentiment.subjectivity, 2),
|
26 |
+
"assessments": assessments}
|
27 |
+
|
28 |
+
# %% app.ipynb 5
|
29 |
+
demo = gr.Interface(fn=analyze_sentiment,
|
30 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
31 |
+
outputs="json",
|
32 |
+
title="Text Sentiment Analysis",
|
33 |
+
description="Analyze the sentiment of text using TextBlob")
|
34 |
+
demo.launch(mcp_server=True)
|
runtime.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python-3.11
|