Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,22 +5,18 @@ from textblob import TextBlob
|
|
| 5 |
def sentiment_analysis(text: str) -> str:
|
| 6 |
"""
|
| 7 |
Analyze the sentiment of the given text.
|
| 8 |
-
|
| 9 |
Args:
|
| 10 |
text (str): The text to analyze
|
| 11 |
-
|
| 12 |
Returns:
|
| 13 |
str: A JSON string containing polarity, subjectivity, and assessment
|
| 14 |
"""
|
| 15 |
blob = TextBlob(text)
|
| 16 |
sentiment = blob.sentiment
|
| 17 |
-
|
| 18 |
result = {
|
| 19 |
"polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
|
| 20 |
"subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
|
| 21 |
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
| 22 |
}
|
| 23 |
-
|
| 24 |
return json.dumps(result)
|
| 25 |
|
| 26 |
# Create the Gradio interface
|
|
@@ -32,12 +28,10 @@ demo = gr.Interface(
|
|
| 32 |
description="Analyze the sentiment of text using TextBlob"
|
| 33 |
)
|
| 34 |
|
| 35 |
-
# Launch the interface
|
| 36 |
if __name__ == "__main__":
|
| 37 |
demo.launch(
|
| 38 |
server_name="0.0.0.0", # Allow external connections
|
| 39 |
-
server_port=7860,
|
| 40 |
-
share=True
|
| 41 |
-
mcp_server=True, # Enable MCP server
|
| 42 |
-
mcp_server_port=8000 # MCP server port
|
| 43 |
)
|
|
|
|
| 5 |
def sentiment_analysis(text: str) -> str:
|
| 6 |
"""
|
| 7 |
Analyze the sentiment of the given text.
|
|
|
|
| 8 |
Args:
|
| 9 |
text (str): The text to analyze
|
|
|
|
| 10 |
Returns:
|
| 11 |
str: A JSON string containing polarity, subjectivity, and assessment
|
| 12 |
"""
|
| 13 |
blob = TextBlob(text)
|
| 14 |
sentiment = blob.sentiment
|
|
|
|
| 15 |
result = {
|
| 16 |
"polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
|
| 17 |
"subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
|
| 18 |
"assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
|
| 19 |
}
|
|
|
|
| 20 |
return json.dumps(result)
|
| 21 |
|
| 22 |
# Create the Gradio interface
|
|
|
|
| 28 |
description="Analyze the sentiment of text using TextBlob"
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# Launch the interface
|
| 32 |
if __name__ == "__main__":
|
| 33 |
demo.launch(
|
| 34 |
server_name="0.0.0.0", # Allow external connections
|
| 35 |
+
server_port=7860, # Standard Gradio port
|
| 36 |
+
share=True # Create public link
|
|
|
|
|
|
|
| 37 |
)
|