File size: 665 Bytes
2cd173a 91978c4 2cd173a 91978c4 2cd173a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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)
|