Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Cargar el modelo
|
| 6 |
+
model_name = "CeciGonSer/translation_espa_pure_biblia_bart-large-cnn" # Reemplaza esto por tu modelo en Hugging Face
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
def translate(text):
|
| 11 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True)
|
| 12 |
+
with torch.no_grad():
|
| 13 |
+
translated = model.generate(**inputs)
|
| 14 |
+
translation = tokenizer.decode(translated[0], skip_special_tokens=True)
|
| 15 |
+
return translation
|
| 16 |
+
|
| 17 |
+
# Interfaz Gradio
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=translate,
|
| 20 |
+
inputs=gr.Textbox(label="Introduce texto en purépecha"),
|
| 21 |
+
outputs=gr.Textbox(label="Traducción al español")
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
interface.launch()
|