rwayz commited on
Commit
aa1f8c6
·
1 Parent(s): 3eb6df4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -214,10 +214,23 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
214
  history_btn.click(toggle_history, inputs=[], outputs=history_output)
215
 
216
  def handle_csv_upload(file):
217
- global engine, db
218
- engine = load_uploaded_csv_and_create_db(file)
219
- if engine is not None:
220
- db = SQLDatabase(engine=engine)
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
  csv_file.change(handle_csv_upload, inputs=csv_file, outputs=csv_file)
223
 
 
214
  history_btn.click(toggle_history, inputs=[], outputs=history_output)
215
 
216
  def handle_csv_upload(file):
217
+ global engine, db, sql_agent
218
+
219
+ try:
220
+ engine = load_uploaded_csv_and_create_db(file)
221
+ if engine is not None:
222
+ db = SQLDatabase(engine=engine)
223
+ sql_agent = create_sql_agent(
224
+ ChatOpenAI(model="gpt-4o-mini", temperature=0),
225
+ db=db,
226
+ agent_type="openai-tools",
227
+ verbose=True,
228
+ max_iterations=40,
229
+ return_intermediate_steps=True
230
+ )
231
+ print("[UPLOAD] Banco e agente SQL atualizados com sucesso.")
232
+ except Exception as e:
233
+ print(f"[ERRO] Falha ao processar novo CSV: {e}")
234
 
235
  csv_file.change(handle_csv_upload, inputs=csv_file, outputs=csv_file)
236