Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
# Load the fine-tuned model and tokenizer
|
5 |
+
model_name = "Addaci/byt5-small-finetuned-yiddish-experiment-10"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Define the translation function
|
10 |
+
def translate_yiddish_to_english(input_text):
|
11 |
+
# Add task instruction to the input
|
12 |
+
prompt = "Translate this Yiddish text in Hebrew script into English text in English script:\n"
|
13 |
+
input_ids = tokenizer(prompt + input_text, return_tensors="pt", truncation=True).input_ids
|
14 |
+
output_ids = model.generate(input_ids, max_length=512)
|
15 |
+
translated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
16 |
+
return translated_text
|
17 |
+
|
18 |
+
# Gradio Interface
|
19 |
+
with gr.Blocks() as interface:
|
20 |
+
gr.Markdown("### Yiddish-to-English Translation Tool")
|
21 |
+
gr.Markdown("Enter a line of Yiddish text in Hebrew script to translate it into English.")
|
22 |
+
|
23 |
+
with gr.Row():
|
24 |
+
input_box = gr.Textbox(label="Input Yiddish Text (Hebrew Script)", lines=1, rtl=True, elem_id="input_box")
|
25 |
+
output_box = gr.Textbox(label="Output English Translation (English Script)", lines=1, rtl=False, elem_id="output_box")
|
26 |
+
|
27 |
+
translate_button = gr.Button("Translate")
|
28 |
+
translate_button.click(translate_yiddish_to_english, inputs=[input_box], outputs=[output_box])
|
29 |
+
|
30 |
+
# Launch the interface
|
31 |
+
interface.launch()
|