File size: 1,252 Bytes
df9751e
 
7b8e261
5ece9aa
b2a650f
37b9209
df9751e
e7a45f0
df9751e
 
 
0079ae6
 
 
 
 
 
 
 
df9751e
 
 
 
 
 
 
 
b2a650f
 
 
 
 
 
df9751e
 
 
 
eed76cc
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
34
35
36
37
38
import gradio as gr
from transformers import MarianMTModel, MarianTokenizer
import torch

# Load the model and tokenizer from the Hub
model_name = "Dddixyy/latin-italian-translatorV5"
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)

# Translation function
def translate_latin_to_italian(latin_text):
    # Make the first letter lowercase if the input is not empty
    if latin_text:
        latin_text = latin_text[0].lower() + latin_text[1:]
    inputs = tokenizer(latin_text, return_tensors="pt", padding=True, truncation=True)
    with torch.no_grad():
        generated_ids = model.generate(inputs["input_ids"])
    translation = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
    return translation[0]

# Define the Gradio interface
interface = gr.Interface(
    fn=translate_latin_to_italian,
    inputs="text",
    outputs="text",
    title="Latin to Italian Translator",
    description="Translate Latin sentences to Italian using a fine-tuned MarianMT model.",
    examples=[
        ["Amor vincit omnia."],
        ["Veni, vidi, vici."],
        ["Carpe diem."],
        ["Alea iacta est."]
    ]
)

# Launch the app
if __name__ == "__main__":
    interface.launch()