|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
|
|
model_name = "Helsinki-NLP/opus-mt-fr-en" |
|
model_name = "Helsinki-NLP/opus-mt-de-en" |
|
|
|
translator = pipeline("translation", model=model_name) |
|
|
|
|
|
def translate_text(text_to_translate): |
|
try: |
|
translated_text = translator(text_to_translate)[0]['translation_text'] |
|
return translated_text |
|
except Exception as e: |
|
return f"Translation Error: {e}" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=translate_text, |
|
inputs=gr.Textbox(lines=5, placeholder="Enter text to translate here..."), |
|
outputs=gr.Textbox(lines=5, label="Translated Text"), |
|
title="Old Text Translator", |
|
description="Translate text using a Hugging Face model. (MVP)", |
|
) |
|
|
|
|
|
iface.launch() |