File size: 684 Bytes
dc290f9
a02892b
 
f6f0134
 
a02892b
dc290f9
 
 
 
 
 
 
 
 
 
 
 
 
f6f0134
 
dc290f9
 
 
 
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
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)