File size: 508 Bytes
a4bbe6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc75086
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from flask import Flask, request, jsonify
from flask_cors import CORS
from sentiment import predict

app = Flask(__name__)
CORS(app)  # Enable CORS for all origins

def analyze_sentiment(text):
    sentiment = predict(text)
    return sentiment

@app.route('/analyze', methods=['POST'])
def analyze():
    data = request.get_json()
    text = data['text']
    sentiment = analyze_sentiment(text)
    return jsonify({'sentiment': sentiment})

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)