File size: 1,001 Bytes
644d5a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# --- Model Loading (Replace with your desired model) ---
# EXAMPLE: French to English.  Choose a model appropriate for your languages!
model_name = "Helsinki-NLP/opus-mt-fr-en"
model_name = "Helsinki-NLP/opus-mt-de-en"

translator = pipeline("translation", model=model_name)

# --- Translation Function ---
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}"  # Basic error handling

# --- Gradio Interface ---
iface = gr.Interface(
    fn=translate_text,
    inputs=gr.Textbox(lines=5, placeholder="Enter text to translate here..."),  # Input textbox
    outputs=gr.Textbox(lines=5, label="Translated Text"),  # Output textbox
    title="Old Text Translator",
    description="Translate text using a Hugging Face model. (MVP)",
)

# --- Launch the App ---
iface.launch()