Anny-Conecta commited on
Commit
003c6df
·
verified ·
1 Parent(s): 4b1ee85

Add app.py with correction logic

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests, os
3
+
4
+ API_URL = "https://api-inference.huggingface.co/models/istartt/GrammarErrorCorrectorV2"
5
+ headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
6
+
7
+ def chat_es(texto):
8
+ respuesta = requests.post(API_URL, headers=headers, json={"inputs": texto})
9
+ data = respuesta.json()
10
+ if isinstance(data, list) and data:
11
+ return data[0].get("generated_text", texto)
12
+ return "❌ Error al procesar. Intenta de nuevo."
13
+
14
+ iface = gr.Interface(
15
+ fn=chat_es,
16
+ inputs=gr.Textbox(lines=4, placeholder="Escribe tu frase en español aquí…"),
17
+ outputs=gr.Textbox(label="Corrección"),
18
+ title="Chat de práctica A2–B1",
19
+ description="Recibe correcciones automáticas de tus frases en español.",
20
+ allow_flagging="never"
21
+ )
22
+
23
+ if __name__ == "__main__":
24
+ iface.launch(server_name="0.0.0.0", server_port=7860)