Update app.py
Browse files
app.py
CHANGED
@@ -103,12 +103,6 @@ def handle_csv_upload(file):
|
|
103 |
logging.error(f"[ERRO] Falha ao processar novo CSV: {e}")
|
104 |
return f"❌ Erro ao processar CSV: {e}"
|
105 |
|
106 |
-
# === Inicialização ===
|
107 |
-
engine = create_engine_and_load_db(get_active_csv_path(), SQL_DB_PATH)
|
108 |
-
db = SQLDatabase(engine=engine)
|
109 |
-
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
|
110 |
-
sql_agent = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True, max_iterations=40, return_intermediate_steps=True)
|
111 |
-
|
112 |
def reset_app():
|
113 |
global engine, db, sql_agent, query_cache, history_log, recent_history
|
114 |
try:
|
@@ -127,15 +121,10 @@ def reset_app():
|
|
127 |
except Exception as e:
|
128 |
return f"❌ Erro ao resetar: {e}"
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
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 (
|
@@ -245,12 +234,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
245 |
with gr.Row():
|
246 |
with gr.Column(scale=1):
|
247 |
gr.Markdown("## ⚙️ Configurações")
|
248 |
-
model_selector = gr.Dropdown(list(LLAMA_MODELS.keys()), label="
|
249 |
-
csv_file = gr.File(label="
|
250 |
upload_feedback = gr.Markdown()
|
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")
|
@@ -279,8 +266,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
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)
|
|
|
103 |
logging.error(f"[ERRO] Falha ao processar novo CSV: {e}")
|
104 |
return f"❌ Erro ao processar CSV: {e}"
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
def reset_app():
|
107 |
global engine, db, sql_agent, query_cache, history_log, recent_history
|
108 |
try:
|
|
|
121 |
except Exception as e:
|
122 |
return f"❌ Erro ao resetar: {e}"
|
123 |
|
124 |
+
engine = create_engine_and_load_db(get_active_csv_path(), SQL_DB_PATH)
|
125 |
+
db = SQLDatabase(engine=engine)
|
126 |
+
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
|
127 |
+
sql_agent = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True, max_iterations=40, return_intermediate_steps=True)
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
def generate_initial_context(db_sample):
|
130 |
return (
|
|
|
234 |
with gr.Row():
|
235 |
with gr.Column(scale=1):
|
236 |
gr.Markdown("## ⚙️ Configurações")
|
237 |
+
model_selector = gr.Dropdown(list(LLAMA_MODELS.keys()), label=" ", value="LLaMA 70B")
|
238 |
+
csv_file = gr.File(label=" ", file_types=[".csv"])
|
239 |
upload_feedback = gr.Markdown()
|
240 |
reset_btn = gr.Button("🔄 Resetar")
|
|
|
|
|
241 |
|
242 |
with gr.Column(scale=4):
|
243 |
gr.Markdown("# 🧠 Anomalia Agent")
|
|
|
266 |
history_btn.click(toggle_history, outputs=history_output)
|
267 |
csv_file.change(handle_csv_and_clear_chat, inputs=csv_file, outputs=[upload_feedback, chatbot])
|
268 |
reset_btn.click(reset_all, outputs=[upload_feedback, chatbot, csv_file])
|
|
|
|
|
269 |
|
270 |
if __name__ == "__main__":
|
271 |
demo.launch(share=False)
|