Update app.py
Browse files
app.py
CHANGED
|
@@ -50,7 +50,6 @@ engine = None
|
|
| 50 |
|
| 51 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 52 |
|
| 53 |
-
# === Controle do CSV ativo ===
|
| 54 |
def get_active_csv_path():
|
| 55 |
"""Retorna o CSV ativo: o carregado ou o padr茫o.."""
|
| 56 |
if os.path.exists(UPLOADED_CSV_PATH):
|
|
@@ -131,12 +130,12 @@ def reset_app():
|
|
| 131 |
def export_history_json():
|
| 132 |
path = "history_log.json"
|
| 133 |
pd.DataFrame(history_log).to_json(path, orient="records", indent=2)
|
| 134 |
-
return
|
| 135 |
|
| 136 |
def export_history_csv():
|
| 137 |
path = "history_log.csv"
|
| 138 |
pd.DataFrame(history_log).to_csv(path, index=False, sep=";")
|
| 139 |
-
return
|
| 140 |
|
| 141 |
def generate_initial_context(db_sample):
|
| 142 |
return (
|
|
@@ -252,7 +251,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 252 |
reset_btn = gr.Button("馃攧 Resetar")
|
| 253 |
export_json = gr.Button("馃摛 Exportar JSON")
|
| 254 |
export_csv = gr.Button("馃摛 Exportar CSV")
|
| 255 |
-
download_output = gr.File(visible=False)
|
| 256 |
|
| 257 |
with gr.Column(scale=4):
|
| 258 |
gr.Markdown("# 馃 Anomalia Agent")
|
|
@@ -261,20 +259,28 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 261 |
btn = gr.Button("Enviar", variant="primary")
|
| 262 |
history_btn = gr.Button("Hist贸rico", variant="secondary")
|
| 263 |
history_output = gr.JSON()
|
|
|
|
| 264 |
|
| 265 |
def respond(message, chat_history, selected_model):
|
| 266 |
response = chatbot_response(message, selected_model)
|
| 267 |
chat_history.append((message, response))
|
| 268 |
return "", chat_history
|
| 269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
msg.submit(respond, [msg, chatbot, model_selector], [msg, chatbot])
|
| 271 |
btn.click(respond, [msg, chatbot, model_selector], [msg, chatbot])
|
| 272 |
history_btn.click(toggle_history, outputs=history_output)
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
export_csv.click(export_history_csv, outputs=download_output)
|
| 278 |
|
| 279 |
if __name__ == "__main__":
|
| 280 |
demo.launch(share=False)
|
|
|
|
| 50 |
|
| 51 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 52 |
|
|
|
|
| 53 |
def get_active_csv_path():
|
| 54 |
"""Retorna o CSV ativo: o carregado ou o padr茫o.."""
|
| 55 |
if os.path.exists(UPLOADED_CSV_PATH):
|
|
|
|
| 130 |
def export_history_json():
|
| 131 |
path = "history_log.json"
|
| 132 |
pd.DataFrame(history_log).to_json(path, orient="records", indent=2)
|
| 133 |
+
return path
|
| 134 |
|
| 135 |
def export_history_csv():
|
| 136 |
path = "history_log.csv"
|
| 137 |
pd.DataFrame(history_log).to_csv(path, index=False, sep=";")
|
| 138 |
+
return path
|
| 139 |
|
| 140 |
def generate_initial_context(db_sample):
|
| 141 |
return (
|
|
|
|
| 251 |
reset_btn = gr.Button("馃攧 Resetar")
|
| 252 |
export_json = gr.Button("馃摛 Exportar JSON")
|
| 253 |
export_csv = gr.Button("馃摛 Exportar CSV")
|
|
|
|
| 254 |
|
| 255 |
with gr.Column(scale=4):
|
| 256 |
gr.Markdown("# 馃 Anomalia Agent")
|
|
|
|
| 259 |
btn = gr.Button("Enviar", variant="primary")
|
| 260 |
history_btn = gr.Button("Hist贸rico", variant="secondary")
|
| 261 |
history_output = gr.JSON()
|
| 262 |
+
download_file = gr.File(visible=False)
|
| 263 |
|
| 264 |
def respond(message, chat_history, selected_model):
|
| 265 |
response = chatbot_response(message, selected_model)
|
| 266 |
chat_history.append((message, response))
|
| 267 |
return "", chat_history
|
| 268 |
|
| 269 |
+
def handle_csv_and_clear_chat(file):
|
| 270 |
+
feedback = handle_csv_upload(file)
|
| 271 |
+
return feedback, []
|
| 272 |
+
|
| 273 |
+
def reset_all():
|
| 274 |
+
feedback = reset_app()
|
| 275 |
+
return feedback, [], None
|
| 276 |
+
|
| 277 |
msg.submit(respond, [msg, chatbot, model_selector], [msg, chatbot])
|
| 278 |
btn.click(respond, [msg, chatbot, model_selector], [msg, chatbot])
|
| 279 |
history_btn.click(toggle_history, outputs=history_output)
|
| 280 |
+
csv_file.change(handle_csv_and_clear_chat, inputs=csv_file, outputs=[upload_feedback, chatbot])
|
| 281 |
+
reset_btn.click(reset_all, outputs=[upload_feedback, chatbot, csv_file])
|
| 282 |
+
export_json.click(lambda: export_history_json(), outputs=download_file)
|
| 283 |
+
export_csv.click(lambda: export_history_csv(), outputs=download_file)
|
|
|
|
| 284 |
|
| 285 |
if __name__ == "__main__":
|
| 286 |
demo.launch(share=False)
|