Update app.py
Browse filesUpdated app.py
app.py
CHANGED
@@ -1,14 +1,25 @@
|
|
1 |
-
import
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Load translation model
|
5 |
translator = pipeline('translation_en_to_uk', model='Helsinki-NLP/opus-mt-en-uk')
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
if text:
|
12 |
translated_text = translator(text, max_length=100)[0]['translation_text']
|
13 |
-
|
14 |
-
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Load translation model
|
5 |
translator = pipeline('translation_en_to_uk', model='Helsinki-NLP/opus-mt-en-uk')
|
6 |
|
7 |
+
# Create Flask app
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
@app.route("/")
|
11 |
+
def home():
|
12 |
+
return open("index.html").read()
|
13 |
+
|
14 |
+
@app.route("/translate", methods=["POST"])
|
15 |
+
def translate():
|
16 |
+
data = request.json
|
17 |
+
text = data.get("text", "")
|
18 |
+
if not text:
|
19 |
+
return jsonify({"error": "No text provided"}), 400
|
20 |
|
|
|
21 |
translated_text = translator(text, max_length=100)[0]['translation_text']
|
22 |
+
return jsonify({"translation": translated_text})
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
app.run(host="0.0.0.0", port=7860)
|