Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
# Load English → Irish
|
| 5 |
+
tokenizer_en_ga = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ga")
|
| 6 |
+
model_en_ga = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-ga")
|
| 7 |
+
|
| 8 |
+
# Load Irish → English
|
| 9 |
+
tokenizer_ga_en = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-ga-en")
|
| 10 |
+
model_ga_en = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-ga-en")
|
| 11 |
+
|
| 12 |
+
def translate(text, direction):
|
| 13 |
+
if direction == "English → Irish":
|
| 14 |
+
inputs = tokenizer_en_ga(text, return_tensors="pt")
|
| 15 |
+
outputs = model_en_ga.generate(**inputs)
|
| 16 |
+
return tokenizer_en_ga.decode(outputs[0], skip_special_tokens=True)
|
| 17 |
+
else:
|
| 18 |
+
inputs = tokenizer_ga_en(text, return_tensors="pt")
|
| 19 |
+
outputs = model_ga_en.generate(**inputs)
|
| 20 |
+
return tokenizer_ga_en.decode(outputs[0], skip_special_tokens=True)
|
| 21 |
+
|
| 22 |
+
interface = gr.Interface(
|
| 23 |
+
fn=translate,
|
| 24 |
+
inputs=[
|
| 25 |
+
gr.Textbox(label="Enter text"),
|
| 26 |
+
gr.Radio(["English → Irish", "Irish → English"], label="Select direction")
|
| 27 |
+
],
|
| 28 |
+
outputs="text",
|
| 29 |
+
title="🇮🇪 GaelLingo",
|
| 30 |
+
description="AI-powered English ↔ Irish Translator"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
interface.launch()
|