-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
31 lines (26 loc) · 1.01 KB
/
app.py
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
28
29
30
31
from flask import Flask, request, jsonify
from models.sentiment_model import analyze_sentiment, analyze_batch, collect_feedback
app = Flask(__name__)
@app.route('/analyze', methods=['POST'])
def analyze():
text = request.json.get('text')
if not text:
return jsonify({"error": "No text provided"}), 400
sentiment = analyze_sentiment(text)
return jsonify({"sentiment": sentiment})
@app.route('/batch-analyze', methods=['POST'])
def batch_analyze():
texts = request.json.get('texts')
if not texts or not isinstance(texts, list):
return jsonify({"error": "Invalid input"}), 400
sentiments = analyze_batch(texts)
return jsonify({"sentiments": sentiments})
@app.route('/feedback', methods=['POST'])
def feedback():
feedback = request.json.get('feedback')
if not feedback:
return jsonify({"error": "No feedback provided"}), 400
collect_feedback(feedback)
return jsonify({"message": "Feedback received"}), 200
if __name__ == '__main__':
app.run(debug=True)