Update app.py
Browse files
app.py
CHANGED
@@ -103,22 +103,29 @@ def generate_text(prompt, max_length=2048):
|
|
103 |
|
104 |
|
105 |
def mostrar_respuesta(pregunta):
|
106 |
-
|
107 |
-
json_obj
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
111 |
try:
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
122 |
return json_obj["respuesta"], json_obj["fuente"], json_obj["tema"]
|
123 |
|
124 |
# Ejemplos de preguntas
|
@@ -136,7 +143,7 @@ iface = gr.Interface(
|
|
136 |
gr.Textbox(label="Fuente", lines=1),
|
137 |
gr.Textbox(label="Tema", lines=1)
|
138 |
],
|
139 |
-
title="
|
140 |
description="Introduce tu pregunta sobre la Constituci贸n Politica o una situaci贸n donde creas que tus derechos hayan sido vulnerados.",
|
141 |
examples=ejemplos,
|
142 |
)
|
|
|
103 |
|
104 |
|
105 |
def mostrar_respuesta(pregunta):
|
106 |
+
respuesta_default = "No se pudo generar una respuesta adecuada."
|
107 |
+
json_obj = {
|
108 |
+
"respuesta": respuesta_default,
|
109 |
+
"fuente": respuesta_default,
|
110 |
+
"tema": respuesta_default
|
111 |
+
}
|
112 |
+
|
113 |
+
if pregunta:
|
114 |
try:
|
115 |
+
res = generate_text(pregunta, max_length=512)
|
116 |
+
inicio_json = res.find('{')
|
117 |
+
fin_json = res.rfind('}') + 1
|
118 |
+
json_str = res[inicio_json:fin_json]
|
119 |
+
json_obj = json.loads(json_str)
|
120 |
+
|
121 |
+
# Verificar si el JSON contiene todas las claves necesarias
|
122 |
+
if all(key in json_obj for key in ["respuesta", "fuente", "tema"]):
|
123 |
+
return json_obj["respuesta"], json_obj["fuente"], json_obj["tema"]
|
124 |
+
else:
|
125 |
+
return res, respuesta_default, respuesta_default
|
126 |
+
except Exception as e:
|
127 |
+
print("Error al procesar la respuesta:", e)
|
128 |
+
|
129 |
return json_obj["respuesta"], json_obj["fuente"], json_obj["tema"]
|
130 |
|
131 |
# Ejemplos de preguntas
|
|
|
143 |
gr.Textbox(label="Fuente", lines=1),
|
144 |
gr.Textbox(label="Tema", lines=1)
|
145 |
],
|
146 |
+
title="HolaaaaaaaaaaaaaaaaaConsulta Juridica basada en la Constitucion Politica del Peru",
|
147 |
description="Introduce tu pregunta sobre la Constituci贸n Politica o una situaci贸n donde creas que tus derechos hayan sido vulnerados.",
|
148 |
examples=ejemplos,
|
149 |
)
|