Spaces:
Sleeping
Sleeping
ratisturua
commited on
Commit
•
b8c4cc5
1
Parent(s):
be3b851
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,3 @@
|
|
1 |
-
import
|
2 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
-
import torch
|
4 |
|
5 |
-
|
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.")
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
gr.load("models/Helsinki-NLP/opus-mt-ka-en").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|