Spaces:
Sleeping
Sleeping
import os | |
import subprocess | |
# Install PyTorch & Transformers if missing | |
try: | |
import torch | |
import transformers | |
except ImportError: | |
subprocess.run(["pip", "install", "torch", "transformers"], check=True) | |
import torch # Re-import after installation | |
import transformers | |
from transformers import pipeline | |
import gradio as gr | |
# Define source and target language | |
src_lang = "eng_Latn" # English | |
tgt_lang = "npi_Deva" # Nepali (Devanagari script) | |
# Load model with language codes | |
model = pipeline("translation", model="BeebekBhz/Final-en-ne", src_lang=src_lang, tgt_lang=tgt_lang) | |
def translate(text): | |
return model(text)[0]['translation_text'] | |
iface = gr.Interface(fn=translate, inputs="text", outputs="text") | |
iface.launch(share=True) |