File size: 604 Bytes
c2864d3
 
fcf5834
c2864d3
 
fcf5834
c2864d3
 
1379c69
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from flask import Flask, request, jsonify
from transformers import pipeline

app = Flask(__name__)
classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True)

@app.route('/classify', methods=['POST'])
def classify():
    try:
        data = request.get_json()
        if 'text' not in data:
            return jsonify({"error": "Missing 'text' field"}), 400
        
        text = data['text']
        result = classifier(text)
        return jsonify(result)
    
    except Exception as e:
        return jsonify({"error": str(e)}), 500