AlexVed commited on
Commit
b3036aa
·
verified ·
1 Parent(s): 5b485b4

Update app.py

Browse files

Updated app.py

Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -1,25 +1,18 @@
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=8080)
 
1
+ import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Load the 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
 
10
+ text = st.text_area("Enter English text:")
 
 
11
 
12
+ if st.button("Translate"):
13
+ if text:
14
+ translated_text = translator(text, max_length=100)[0]['translation_text']
15
+ st.subheader("Translation:")
16
+ st.write(translated_text)
17
+ else:
18
+ st.warning("Please enter text to translate.")