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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -69,6 +69,8 @@ def load_uploaded_csv_and_create_db(uploaded_file):
69
  df = pd.read_csv(uploaded_file, sep=";", on_bad_lines="skip")
70
  df.to_sql("anomalia_vendas", engine, index=False, if_exists="replace")
71
  print("Banco recriado com base no novo CSV.")
 
 
72
  return engine
73
 
74
  engine = create_or_load_sql_database(CSV_FILE_PATH, SQL_DB_PATH)
@@ -212,9 +214,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
212
  history_btn.click(toggle_history, inputs=[], outputs=history_output)
213
 
214
  def handle_csv_upload(file):
215
- global engine
216
  engine = load_uploaded_csv_and_create_db(file)
217
- return gr.update(value=None)
 
218
 
219
  csv_file.change(handle_csv_upload, inputs=csv_file, outputs=csv_file)
220
 
 
69
  df = pd.read_csv(uploaded_file, sep=";", on_bad_lines="skip")
70
  df.to_sql("anomalia_vendas", engine, index=False, if_exists="replace")
71
  print("Banco recriado com base no novo CSV.")
72
+ print(f"CSV carregado: {len(df)} linhas, {len(df.columns)} colunas")
73
+ print(f"[DEBUG] Novo engine criado: {engine}")
74
  return engine
75
 
76
  engine = create_or_load_sql_database(CSV_FILE_PATH, SQL_DB_PATH)
 
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