Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ load_dotenv()
|
|
16 |
UPLOAD_DIR = "uploaded_data"
|
17 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
18 |
|
19 |
-
DEFAULT_CSV_PATH = "
|
20 |
UPLOADED_CSV_PATH = os.path.join(UPLOAD_DIR, "tabela.csv")
|
21 |
SQL_DB_PATH = "data.db"
|
22 |
|
@@ -64,7 +64,7 @@ def create_engine_and_load_db(csv_path, sql_db_path):
|
|
64 |
logging.info(f"[ENGINE] Criando engine com CSV: {csv_path}")
|
65 |
engine = create_engine(f"sqlite:///{sql_db_path}")
|
66 |
df = pd.read_csv(csv_path, sep=";", on_bad_lines="skip")
|
67 |
-
df.to_sql("
|
68 |
logging.info(f"[ENGINE] Banco criado com sucesso com {len(df)} linhas e {len(df.columns)} colunas")
|
69 |
return engine
|
70 |
|
@@ -153,7 +153,7 @@ def query_sql_agent(user_query, selected_model_name):
|
|
153 |
query_cache[user_query] = greeting_response
|
154 |
return greeting_response
|
155 |
|
156 |
-
column_data = pd.read_sql_query("SELECT * FROM
|
157 |
llama_instruction = query_with_llama(user_query, column_data, selected_model_name)
|
158 |
|
159 |
if not llama_instruction:
|
|
|
16 |
UPLOAD_DIR = "uploaded_data"
|
17 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
18 |
|
19 |
+
DEFAULT_CSV_PATH = "tabela.csv"
|
20 |
UPLOADED_CSV_PATH = os.path.join(UPLOAD_DIR, "tabela.csv")
|
21 |
SQL_DB_PATH = "data.db"
|
22 |
|
|
|
64 |
logging.info(f"[ENGINE] Criando engine com CSV: {csv_path}")
|
65 |
engine = create_engine(f"sqlite:///{sql_db_path}")
|
66 |
df = pd.read_csv(csv_path, sep=";", on_bad_lines="skip")
|
67 |
+
df.to_sql("tabela", engine, index=False, if_exists="replace")
|
68 |
logging.info(f"[ENGINE] Banco criado com sucesso com {len(df)} linhas e {len(df.columns)} colunas")
|
69 |
return engine
|
70 |
|
|
|
153 |
query_cache[user_query] = greeting_response
|
154 |
return greeting_response
|
155 |
|
156 |
+
column_data = pd.read_sql_query("SELECT * FROM tabela LIMIT 10", engine)
|
157 |
llama_instruction = query_with_llama(user_query, column_data, selected_model_name)
|
158 |
|
159 |
if not llama_instruction:
|