tsl / app.py
d1d9's picture
Create app.py
644d5a1 verified
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()