Spaces:
Sleeping
Sleeping
Update app_front.py
Browse files- app_front.py +20 -3
app_front.py
CHANGED
|
@@ -54,10 +54,23 @@ def analizar_foto(token, imagen):
|
|
| 54 |
img_res = Image.open(io.BytesIO(res.content))
|
| 55 |
return f"## 🤖 Agente Dice:\n{msg}\n\n**Objeto:** {det}", img_res
|
| 56 |
elif res.status_code == 429:
|
| 57 |
-
return f"
|
| 58 |
-
return f"
|
| 59 |
except Exception as e:
|
| 60 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
@@ -103,6 +116,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 103 |
img_output = gr.Image()
|
| 104 |
|
| 105 |
btn_scan.click(analizar_foto, [token_state, img_input], [txt_output, img_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 54 |
img_res = Image.open(io.BytesIO(res.content))
|
| 55 |
return f"## 🤖 Agente Dice:\n{msg}\n\n**Objeto:** {det}", img_res
|
| 56 |
elif res.status_code == 429:
|
| 57 |
+
return f" **Rate Limit:** {res.json().get('detail')}", None
|
| 58 |
+
return f" Error en API: {res.text}", None
|
| 59 |
except Exception as e:
|
| 60 |
+
return f" Error: {str(e)}", None
|
| 61 |
+
|
| 62 |
+
def ver_historial(token):
|
| 63 |
+
if not token: return "Inicia sesión primero."
|
| 64 |
+
headers = {"Authorization": f"Bearer {token}"}
|
| 65 |
+
res = requests.get(f"{API_URL}/historial/me", headers=headers)
|
| 66 |
+
if res.status_code == 200:
|
| 67 |
+
h = res.json()
|
| 68 |
+
texto = "### Tu historial de reciclaje:\n"
|
| 69 |
+
for item in h:
|
| 70 |
+
texto += f"**{item['fecha'][:10]}**: {item['mensaje_usuario']}\n"
|
| 71 |
+
texto += f"> 🤖 {item['respuesta_agente']}\n\n--- \n"
|
| 72 |
+
return texto
|
| 73 |
+
return "No se pudo cargar el historial."
|
| 74 |
|
| 75 |
|
| 76 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
|
|
| 116 |
img_output = gr.Image()
|
| 117 |
|
| 118 |
btn_scan.click(analizar_foto, [token_state, img_input], [txt_output, img_output])
|
| 119 |
+
with gr.TabItem("📜 Historial"):
|
| 120 |
+
btn_hist = gr.Button("Cargar mi Historial")
|
| 121 |
+
out_hist = gr.Markdown()
|
| 122 |
+
btn_hist.click(ver_historial, [token_state], out_hist)
|
| 123 |
|
| 124 |
if __name__ == "__main__":
|
| 125 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|