from flask import Flask, request, jsonify from transformers import pipeline app = Flask(__name__) translator = pipeline("translation", model="Bildad/Swahili-English_Translation") @app.route("/translate", methods=["POST"]) def translate(): data = request.get_json() if "text" not in data: return jsonify({"error": "No text provided"}), 400 text_to_translate = data["text"] translation = translator(text_to_translate)[0] translated_text = translation["translation_text"] return jsonify({"translated_text": translated_text}) if __name__ == "__main__": from waitress import serve serve(app, host="0.0.0.0", port=10000)