mpolanco commited on
Commit
01b9e6c
1 Parent(s): eae3e01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -28
app.py CHANGED
@@ -1,39 +1,17 @@
1
  import gradio as gr
2
  import requests
3
 
4
- def pregunta_law_guatemala(pregunta):
5
- # Definir los datos necesarios para la llamada a la API
6
  url = "https://api.afforai.com/api/api_completion"
7
- headers = {"Content-Type": "application/json"}
8
- payload = {
9
  "apiKey": "fcbfdfe8-e9ed-41f3-a7d8-b6587538e84e",
10
  "sessionID": "65489d7c9ad727940f2ab26f",
11
- "history": [{"role": "user", "content": pregunta}],
12
  "powerful": False,
13
  "google": True
14
  }
 
 
15
 
16
- # Realizar la solicitud POST a la API
17
- response = requests.post(url, json=payload, headers=headers)
18
-
19
- # Verificar si la solicitud fue exitosa
20
- if response.status_code == 200:
21
- data = response.json()
22
- respuesta = data["completion"]
23
- else:
24
- respuesta = "Ocurrió un error al procesar la pregunta. Inténtalo de nuevo más tarde."
25
-
26
- return respuesta
27
-
28
- # Crear la interfaz Gradio
29
- iface = gr.Interface(
30
- fn=pregunta_law_guatemala,
31
- inputs="text",
32
- outputs="text",
33
- title="Preguntas sobre las leyes de Guatemala",
34
- description="Haz una pregunta sobre las leyes de Guatemala y obtén una respuesta.",
35
- theme="compact"
36
- )
37
-
38
- # Ejecutar la aplicación
39
  iface.launch()
 
1
  import gradio as gr
2
  import requests
3
 
4
+ def ask_question(question):
 
5
  url = "https://api.afforai.com/api/api_completion"
6
+ data = {
 
7
  "apiKey": "fcbfdfe8-e9ed-41f3-a7d8-b6587538e84e",
8
  "sessionID": "65489d7c9ad727940f2ab26f",
9
+ "history": [{"role": "user", "content": question}],
10
  "powerful": False,
11
  "google": True
12
  }
13
+ response = requests.post(url, json=data)
14
+ return response.json()
15
 
16
+ iface = gr.Interface(fn=ask_question, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  iface.launch()