Spaces:
Sleeping
Sleeping
File size: 1,098 Bytes
003c6df 5147536 003c6df 5147536 003c6df 5147536 0f0516e 5147536 003c6df 5147536 003c6df 5147536 003c6df 7c027b9 5147536 0f0516e 7c027b9 31c1c33 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
import requests
import os
API_URL = "https://api-inference.huggingface.co/models/unbabel/gec-t5_small"
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
def chat_es(texto):
prompt = (
"Corrige la gramática de este texto en español y devuelve solo la frase corregida:\n\n"
+ texto
)
resp = requests.post(API_URL, headers=headers, json={"inputs": prompt})
# Si la API responde con error HTTP
if resp.status_code != 200:
return f"🛑 Error HTTP {resp.status_code}: {resp.json().get('error', resp.text)}"
data = resp.json()
# Extraemos el texto generado
if isinstance(data, list) and data:
return data[0].get("generated_text", texto)
return "ℹ️ No se obtuvo corrección"
iface = gr.Interface(
fn=chat_es,
inputs=gr.Textbox(lines=4, placeholder="Escribe tu frase aquí…"),
outputs=gr.Textbox(label="Corrección"),
title="Chat de práctica A2–B1",
description="Recibe correcciones automáticas de tus frases en español.",
flagging_mode="never"
)
iface.launch()
|