Spaces:
Sleeping
Sleeping
Commit
·
596475f
1
Parent(s):
67a3451
Write app.py
Browse filesCreating a basic Flask server file
app.py
CHANGED
@@ -1,37 +1,14 @@
|
|
1 |
-
import
|
2 |
-
import gradio as gr
|
3 |
-
from textblob import TextBlob
|
4 |
|
5 |
-
|
6 |
-
"""
|
7 |
-
Analyze the sentiment of the given text.
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
|
13 |
-
|
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 |
-
|
25 |
-
|
26 |
-
# Create the Gradio interface
|
27 |
-
demo = gr.Interface(
|
28 |
-
fn=sentiment_analysis,
|
29 |
-
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
30 |
-
outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
|
31 |
-
title="Text Sentiment Analysis",
|
32 |
-
description="Analyze the sentiment of text using TextBlob"
|
33 |
-
)
|
34 |
-
|
35 |
-
# Launch the interface and MCP server
|
36 |
-
if __name__ == "__main__":
|
37 |
-
demo.launch(mcp_server=True)
|
|
|
1 |
+
from flask import Flask, jsonify
|
|
|
|
|
2 |
|
3 |
+
app = Flask(__name__)
|
|
|
|
|
4 |
|
5 |
+
@app.route('/')
|
6 |
+
def home():
|
7 |
+
return jsonify({"message": "Hello, World!"})
|
8 |
|
9 |
+
@app.route('/health')
|
10 |
+
def health():
|
11 |
+
return jsonify({"status": "ok"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
if __name__ == '__main__':
|
14 |
+
app.run(host='0.0.0.0', port=5000, debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|