Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,11 @@ from transformers import pipeline, T5Tokenizer, T5ForConditionalGeneration
|
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Cargar el token de Hugging Face
|
| 7 |
token = os.getenv("HF_TOKEN")
|
| 8 |
if not token:
|
| 9 |
raise ValueError("El token no se configuró correctamente en las variables de entorno del Espacio.")
|
| 10 |
|
| 11 |
-
# Configuración de los headers para la API con el token
|
| 12 |
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-es"
|
| 13 |
headers = {"Authorization": f"Bearer {token}"}
|
| 14 |
|
|
@@ -21,23 +20,20 @@ summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
|
|
| 21 |
def texto_sum(text):
|
| 22 |
# Resumir el texto de entrada
|
| 23 |
summary = summarizer(text, do_sample=False)[0]['summary_text']
|
| 24 |
-
|
| 25 |
# Realizar la traducción del resumen utilizando la API de Hugging Face
|
| 26 |
response = requests.post(API_URL, headers=headers, json={"inputs": summary})
|
| 27 |
translation = response.json()
|
| 28 |
-
|
| 29 |
# Verificar si hay errores en la respuesta de la traducción
|
| 30 |
if 'error' in translation:
|
| 31 |
return f"Error en la traducción: {translation['error']}"
|
| 32 |
|
| 33 |
return translation[0]['translation_text']
|
| 34 |
-
|
| 35 |
# Interfaz de Gradio
|
| 36 |
demo = gr.Interface(
|
| 37 |
fn=texto_sum,
|
| 38 |
inputs=gr.Textbox(label="Texto a introducir:", placeholder="Introduce el texto a resumir aquí..."),
|
| 39 |
outputs="text"
|
| 40 |
)
|
| 41 |
-
|
| 42 |
# Lanzar la interfaz
|
| 43 |
demo.launch()
|
|
|
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# Cargar el token de Hugging Face configurado en el espacio
|
| 7 |
token = os.getenv("HF_TOKEN")
|
| 8 |
if not token:
|
| 9 |
raise ValueError("El token no se configuró correctamente en las variables de entorno del Espacio.")
|
| 10 |
|
|
|
|
| 11 |
API_URL = "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-es"
|
| 12 |
headers = {"Authorization": f"Bearer {token}"}
|
| 13 |
|
|
|
|
| 20 |
def texto_sum(text):
|
| 21 |
# Resumir el texto de entrada
|
| 22 |
summary = summarizer(text, do_sample=False)[0]['summary_text']
|
|
|
|
| 23 |
# Realizar la traducción del resumen utilizando la API de Hugging Face
|
| 24 |
response = requests.post(API_URL, headers=headers, json={"inputs": summary})
|
| 25 |
translation = response.json()
|
|
|
|
| 26 |
# Verificar si hay errores en la respuesta de la traducción
|
| 27 |
if 'error' in translation:
|
| 28 |
return f"Error en la traducción: {translation['error']}"
|
| 29 |
|
| 30 |
return translation[0]['translation_text']
|
| 31 |
+
|
| 32 |
# Interfaz de Gradio
|
| 33 |
demo = gr.Interface(
|
| 34 |
fn=texto_sum,
|
| 35 |
inputs=gr.Textbox(label="Texto a introducir:", placeholder="Introduce el texto a resumir aquí..."),
|
| 36 |
outputs="text"
|
| 37 |
)
|
|
|
|
| 38 |
# Lanzar la interfaz
|
| 39 |
demo.launch()
|