Spaces:
Sleeping
Sleeping
from flask import Flask, request, jsonify | |
from transformers import pipeline | |
app = Flask(__name__) | |
# Define label mappings | |
id2label = {0: "not_bullying", 1: "bullying"} | |
label2id = {"not_bullying": 0, "bullying": 1} | |
# Load the text classification pipeline with label mappings | |
classifier = pipeline( | |
"text-classification", | |
model="Davephoenix/bert-bullying-detector", | |
id2label=id2label, | |
label2id=label2id, | |
) | |
def classify_text(): | |
data = request.get_json() | |
if not data or "text" not in data: | |
return jsonify({"error": "Missing 'text' in request body"}), 400 | |
try: | |
result = classifier(data["text"]) | |
return jsonify(result) | |
except Exception as e: | |
return jsonify({"error": str(e)}), 500 | |
def classify_audio(): | |
return jsonify({"error": "Audio classification not implemented yet"}), 501 | |
def classify_image(): | |
return jsonify({"error": "Image classification not implemented yet"}), 501 | |
if __name__ == "__main__": | |
app.run(host="0.0.0.0", port=7860) | |