Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,13 @@ def sentiment_analysis(text: str) -> dict:
|
|
| 11 |
Returns:
|
| 12 |
dict: A dictionary containing polarity, subjectivity, and assessment
|
| 13 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
blob = TextBlob(text)
|
| 15 |
sentiment = blob.sentiment
|
| 16 |
|
|
@@ -23,12 +30,18 @@ def sentiment_analysis(text: str) -> dict:
|
|
| 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
|
| 33 |
if __name__ == "__main__":
|
| 34 |
-
demo.launch(
|
|
|
|
| 11 |
Returns:
|
| 12 |
dict: A dictionary containing polarity, subjectivity, and assessment
|
| 13 |
"""
|
| 14 |
+
if not text.strip():
|
| 15 |
+
return {
|
| 16 |
+
"polarity": 0.0,
|
| 17 |
+
"subjectivity": 0.0,
|
| 18 |
+
"assessment": "neutral"
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
blob = TextBlob(text)
|
| 22 |
sentiment = blob.sentiment
|
| 23 |
|
|
|
|
| 30 |
# Create the Gradio interface
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=sentiment_analysis,
|
| 33 |
+
inputs=gr.Textbox(placeholder="Enter text to analyze...", label="Text Input"),
|
| 34 |
+
outputs=gr.JSON(label="Sentiment Analysis Results"),
|
| 35 |
title="Text Sentiment Analysis",
|
| 36 |
+
description="Analyze the sentiment of text using TextBlob. Returns polarity (-1 to 1), subjectivity (0 to 1), and overall assessment.",
|
| 37 |
+
examples=[
|
| 38 |
+
["I love this product! It's amazing!"],
|
| 39 |
+
["This is terrible and I hate it."],
|
| 40 |
+
["The weather is okay today."],
|
| 41 |
+
["Python is a programming language."]
|
| 42 |
+
]
|
| 43 |
)
|
| 44 |
|
| 45 |
+
# Launch the interface
|
| 46 |
if __name__ == "__main__":
|
| 47 |
+
demo.launch()
|