AlexVed commited on
Commit
dc290f9
·
verified ·
1 Parent(s): a011039

Update app.py

Browse files

Updated app.py

Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -1,14 +1,25 @@
1
- import streamlit as st
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
- # Streamlit UI
8
- st.title("English to Ukrainian Translator")
9
- text = st.text_area("Enter English text:")
 
 
 
 
 
 
 
 
 
 
10
 
11
- if text:
12
  translated_text = translator(text, max_length=100)[0]['translation_text']
13
- st.subheader("Translation:")
14
- st.write(translated_text)
 
 
 
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)