Spaces:
Runtime error
Runtime error
second commit
Browse files
app.py
CHANGED
|
@@ -1,7 +1,26 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
+
# Load your Hugging Face model and tokenizer
|
| 5 |
+
model_name = "dreyyyy/EN-ES" # Replace with your model ID
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
+
# Define the prediction function
|
| 10 |
+
def translate_text(input_text):
|
| 11 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 12 |
+
outputs = model.generate(**inputs)
|
| 13 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
+
|
| 15 |
+
# Create the Gradio interface
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=translate_text,
|
| 18 |
+
inputs="text",
|
| 19 |
+
outputs="text",
|
| 20 |
+
title="Text Translation",
|
| 21 |
+
description="Translate input text using a Hugging Face model."
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch the Gradio app
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
iface.launch()
|