Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,31 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
demo.launch(debug=True)
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
2 |
import gradio as gr
|
3 |
+
|
4 |
+
# Load the pre-trained model and tokenizer
|
5 |
+
model_ckpt = "booba-uz/english-uzbek-translation_v1"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_ckpt)
|
8 |
+
|
9 |
+
# Set source and target languages for the tokenizer
|
10 |
+
tokenizer.src_lang = "en"
|
11 |
+
tokenizer.tgt_lang = "uz"
|
12 |
+
|
13 |
+
# Define the translation function
|
14 |
+
def translator(input_text):
|
15 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
16 |
+
outputs = model.generate(**inputs, max_length=256)
|
17 |
+
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
return translated_text
|
19 |
+
|
20 |
+
# Reset function for canceling the input
|
21 |
+
def reset_input():
|
22 |
+
return "", # Reset input text
|
23 |
+
|
24 |
+
# Create Gradio interface with Submit and Cancel buttons
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=translator,
|
27 |
+
inputs="text",
|
28 |
+
outputs="text",
|
29 |
+
)
|
30 |
+
|
31 |
demo.launch(debug=True)
|