Dddixyy commited on
Commit
df9751e
·
verified ·
1 Parent(s): bcaef11

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import MarianMTModel, MarianTokenizer
3
+
4
+ # Load the model and tokenizer from the Hub
5
+ model_name = "Dddixyy/latin-italian-translator"
6
+ tokenizer = MarianTokenizer.from_pretrained(model_name)
7
+ model = MarianMTModel.from_pretrained(model_name)
8
+
9
+ # Translation function
10
+ def translate_latin_to_italian(latin_text):
11
+ inputs = tokenizer(latin_text, return_tensors="pt", padding=True, truncation=True)
12
+ with torch.no_grad():
13
+ generated_ids = model.generate(inputs["input_ids"])
14
+ translation = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
15
+ return translation[0]
16
+
17
+ # Define the Gradio interface
18
+ interface = gr.Interface(
19
+ fn=translate_latin_to_italian,
20
+ inputs="text",
21
+ outputs="text",
22
+ title="Latin to Italian Translator",
23
+ description="Translate Latin sentences to Italian using a fine-tuned MarianMT model.",
24
+ examples=[
25
+ ["Amor vincit omnia."],
26
+ ["Veni, vidi, vici."],
27
+ ["Carpe diem."],
28
+ ["Alea iacta est."]
29
+ ]
30
+ )
31
+
32
+ # Launch the app
33
+ if __name__ == "__main__":
34
+ interface.launch()