import gradio as gr from transformers import MarianMTModel, MarianTokenizer # Load the model and tokenizer for English-to-Italian translation model_name = "Helsinki-NLP/opus-mt-en-it" tokenizer = MarianTokenizer.from_pretrained(model_name) model = MarianMTModel.from_pretrained(model_name) # Translation function def translate_to_italian(text): inputs = tokenizer(text, return_tensors="pt", truncation=True) outputs = model.generate(**inputs) translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) return translated_text # Set up Gradio Interface iface = gr.Interface( fn=translate_to_italian, inputs="text", outputs="text", title="English to Italian Translator", description="Enter English text to get the Italian translation." ) # Launch the interface iface.launch(share=True)