chat-es-anny / app.py
Anny-Conecta's picture
Add app.py with correction logic
003c6df verified
raw
history blame
869 Bytes
import gradio as gr
import requests, os
API_URL = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fistartt%2FGrammarErrorCorrectorV2%26quot%3B%3C%2Fspan%3E%3C!-- HTML_TAG_END -->
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
def chat_es(texto):
respuesta = requests.post(API_URL, headers=headers, json={"inputs": texto})
data = respuesta.json()
if isinstance(data, list) and data:
return data[0].get("generated_text", texto)
return "❌ Error al procesar. Intenta de nuevo."
iface = gr.Interface(
fn=chat_es,
inputs=gr.Textbox(lines=4, placeholder="Escribe tu frase en español 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.",
allow_flagging="never"
)
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860)