Spaces:
Sleeping
Sleeping
ratisturua
commited on
Commit
•
be3b851
1
Parent(s):
66f7a3b
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,36 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
st.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
|
5 |
+
# Display the torch version (optional, for verification)
|
6 |
+
st.sidebar.write(f'PyTorch Version: {torch.__version__}')
|
7 |
+
|
8 |
+
# Load models and tokenizers for both directions
|
9 |
+
models = {
|
10 |
+
"ka-en": {
|
11 |
+
"model": AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-ka-en"),
|
12 |
+
"tokenizer": AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-ka-en")
|
13 |
+
},
|
14 |
+
"en-ka": {
|
15 |
+
# Assuming this model is correctly specified
|
16 |
+
"model": AutoModelForSeq2SeqLM.from_pretrained("SoyGema/english-georgian", use_auth_token=True if st.secrets["HF_TOKEN"] else None),
|
17 |
+
"tokenizer": AutoTokenizer.from_pretrained("SoyGema/english-georgian", use_auth_token=True if st.secrets["HF_TOKEN"] else None)
|
18 |
+
}
|
19 |
+
}
|
20 |
+
|
21 |
+
# UI for selecting translation direction
|
22 |
+
direction = st.selectbox("Select translation direction:", options=["ka-en", "en-ka"], index=0)
|
23 |
+
|
24 |
+
# UI for input text
|
25 |
+
text = st.text_area("Text to translate:", height=150)
|
26 |
+
|
27 |
+
if st.button('Translate'):
|
28 |
+
if text:
|
29 |
+
tokenizer = models[direction]['tokenizer']
|
30 |
+
model = models[direction]['model']
|
31 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
32 |
+
translated = model.generate(**inputs)
|
33 |
+
translation = tokenizer.decode(translated[0], skip_special_tokens=True)
|
34 |
+
st.write(translation)
|
35 |
+
else:
|
36 |
+
st.write("Please enter some text to translate.")
|