-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
27 lines (21 loc) · 660 Bytes
/
app.py
File metadata and controls
27 lines (21 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# app.py
from flask import Flask, request, jsonify
from textblob import TextBlob
app = Flask(__name__)
@app.route('/analyze', methods=['POST'])
def analyze_sentiment():
data = request.get_json()
text = data.get('text', '')
if not text:
return jsonify({'error': 'No text provided'}), 400
analysis = TextBlob(text)
sentiment_score = analysis.sentiment.polarity
if sentiment_score > 0:
sentiment = 'positive'
elif sentiment_score < 0:
sentiment = 'negative'
else:
sentiment = 'neutral'
return jsonify({'sentiment': sentiment})
if __name__ == '__main__':
app.run(debug=True, port=5000)