Spaces:
Sleeping
Sleeping
| 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) | |
| 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 | |