TestApp / app.py
AlexVed's picture
Update app.py
dc290f9 verified
raw
history blame
684 Bytes
from flask import Flask, request, jsonify
from transformers import pipeline
# Load translation model
translator = pipeline('translation_en_to_uk', model='Helsinki-NLP/opus-mt-en-uk')
# Create Flask app
app = Flask(__name__)
@app.route("/")
def home():
return open("index.html").read()
@app.route("/translate", methods=["POST"])
def translate():
data = request.json
text = data.get("text", "")
if not text:
return jsonify({"error": "No text provided"}), 400
translated_text = translator(text, max_length=100)[0]['translation_text']
return jsonify({"translation": translated_text})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)