ratisturua commited on
Commit
2e4da92
1 Parent(s): b8c4cc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -2
app.py CHANGED
@@ -1,3 +1,30 @@
1
- import gradio as gr
 
 
2
 
3
- gr.load("models/Helsinki-NLP/opus-mt-ka-en").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
+ import torch
4
 
5
+ # Optionally display the torch version for verification
6
+ st.sidebar.write(f'PyTorch Version: {torch.__version__}')
7
+
8
+ # Load the model and tokenizer for Georgian to English translation
9
+ model_name = "Helsinki-NLP/opus-mt-ka-en"
10
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
11
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
12
+
13
+ # UI Title
14
+ st.title("Georgian to English Translator")
15
+
16
+ # UI for input text
17
+ text = st.text_area("Enter Georgian text:", height=150)
18
+
19
+ if st.button('Translate'):
20
+ if text:
21
+ # Prepare the text for translation
22
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
23
+ # Translate the text
24
+ translated = model.generate(**inputs)
25
+ # Decode the translated text
26
+ translation = tokenizer.decode(translated[0], skip_special_tokens=True)
27
+ # Display the translation
28
+ st.write(translation)
29
+ else:
30
+ st.write("Please enter some text to translate.")