Spaces:
Sleeping
Sleeping
Ari
commited on
Update app.py
Browse files
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
|
30 |
-
|
|
|
|
|
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
|
42 |
-
db.raw_connection = conn # Use the
|
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(
|