Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import os | |
| API_URL = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Funbabel%2Fgec-t5_small%26quot%3B%3C%2Fspan%3E%3C!-- HTML_TAG_END --> | |
| 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() | |