Ari commited on
Commit
36fba91
·
verified ·
1 Parent(s): a511dd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -26,8 +26,10 @@ else:
26
  st.write(f"Data Preview ({csv_file.name}):")
27
  st.dataframe(data.head())
28
 
29
- # Step 2: Load CSV data into SQLite database with dynamic table name
30
- conn = sqlite3.connect(':memory:') # Use an in-memory SQLite database
 
 
31
  table_name = csv_file.name.split('.')[0] if csv_file else "default_table"
32
  data.to_sql(table_name, conn, index=False, if_exists='replace')
33
 
@@ -38,8 +40,8 @@ valid_columns = list(data.columns)
38
  st.write(f"Valid columns: {valid_columns}")
39
 
40
  # Step 3: Set up the SQL Database for LangChain
41
- db = SQLDatabase.from_uri('sqlite:///:memory:')
42
- db.raw_connection = conn # Use the in-memory connection for LangChain
43
 
44
  # Step 4: Create the SQL agent with increased iteration and time limits
45
  sql_agent = create_sql_agent(
 
26
  st.write(f"Data Preview ({csv_file.name}):")
27
  st.dataframe(data.head())
28
 
29
+ # Step 2: Load CSV data into a persistent SQLite database
30
+ # Use a persistent database file instead of in-memory to retain schema context
31
+ db_file = 'my_database.db'
32
+ conn = sqlite3.connect(db_file)
33
  table_name = csv_file.name.split('.')[0] if csv_file else "default_table"
34
  data.to_sql(table_name, conn, index=False, if_exists='replace')
35
 
 
40
  st.write(f"Valid columns: {valid_columns}")
41
 
42
  # Step 3: Set up the SQL Database for LangChain
43
+ db = SQLDatabase.from_uri(f'sqlite:///{db_file}')
44
+ db.raw_connection = conn # Use the persistent database connection for LangChain
45
 
46
  # Step 4: Create the SQL agent with increased iteration and time limits
47
  sql_agent = create_sql_agent(