guge123 commited on
Commit
fb23813
1 Parent(s): 47f9b61

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from transformers import pipeline
3
+
4
+ app = Flask(__name__)
5
+ model = pipeline("sentiment-analysis")
6
+
7
+ @app.route('/predict', methods=['POST'])
8
+ def predict_sentiment():
9
+ text = request.json.get('text')
10
+ if not text:
11
+ return jsonify({'error': 'Text field is missing'}), 400
12
+
13
+ result = model(text)
14
+ return jsonify({'sentiment': result[0]['label'], 'confidence': result[0]['score']})
15
+
16
+ if __name__ == '__main__':
17
+ app.run(debug=True, host='0.0.0.0')