File size: 1,238 Bytes
cbd4236
 
6a55382
807c806
cbd4236
 
cfb35b2
 
3fa3145
cbd4236
 
3fa3145
cbd4236
 
c79065d
cbd4236
 
 
c79065d
6a55382
 
 
 
5bc1ff1
6a55382
07b1cfd
 
 
 
 
 
db71679
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import torch
from transformers import MarianMTModel, MarianTokenizer
import gradio as gr

def translate_hebrew_to_english(hebrew_text):
    # Load the tokenizer and model
    tokenizer = MarianTokenizer.from_pretrained("model_files", source_lang="he", target_lang="en")
    model = MarianMTModel.from_pretrained("model_files")

    # Tokenize the input text
    inputs = tokenizer.encode(hebrew_text, return_tensors="pt")

    # Translate the input text
    outputs = model.generate(inputs, max_length=512)

    # Decode the translated text
    translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return translated_text

# Define the translation function for Gradio
def translate(input_text):
    translated_text = translate_hebrew_to_english(input_text)
    return translated_text

# Create the Gradio interface
iface = gr.Interface(fn=translate, 
                     inputs=gr.inputs.Textbox(lines=10, placeholder="Paste your Hebrew text here"),
                     outputs=gr.outputs.Textbox(),
                     title="Hebrew to English Translator",
                     layout="vertical",
                     css=".input textarea { height: 300px; } .output textarea { height: 300px; }")
iface.launch()