AI-ANK commited on
Commit
2ebcbe2
·
verified ·
1 Parent(s): 15dea90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -29,6 +29,8 @@ from llama_index.query_engine.retriever_query_engine import (
29
  RetrieverQueryEngine,
30
  )
31
 
 
 
32
  st.set_page_config(layout="wide")
33
  write_dir = Path("textdata")
34
 
@@ -193,6 +195,15 @@ if st.button("Submit Query"):
193
  df2 = df.drop('text', axis=1)
194
  #Create a SQLite database and engine
195
  engine = create_engine("sqlite:///NY_House_Dataset.db?mode=ro", connect_args={"uri": True})
 
 
 
 
 
 
 
 
 
196
  sql_database = SQLDatabase(engine)
197
  #Convert the DataFrame to a SQL table within the SQLite database
198
  df2.to_sql('housing_data_sql', con=engine, if_exists='replace', index=False)
 
29
  RetrieverQueryEngine,
30
  )
31
 
32
+ from sqlalchemy import text, event
33
+
34
  st.set_page_config(layout="wide")
35
  write_dir = Path("textdata")
36
 
 
195
  df2 = df.drop('text', axis=1)
196
  #Create a SQLite database and engine
197
  engine = create_engine("sqlite:///NY_House_Dataset.db?mode=ro", connect_args={"uri": True})
198
+
199
+ @event.listens_for(engine, "before_cursor_execute")
200
+ def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany):
201
+ if statement.strip().lower().startswith(("insert", "update", "delete")):
202
+ # Instead of raising an error, log or print a warning
203
+ print("Read-only mode: Modification attempt blocked.")
204
+ # Prevent execution by skipping the operation
205
+ raise Exception("Attempted to modify the database in read-only mode.")
206
+
207
  sql_database = SQLDatabase(engine)
208
  #Convert the DataFrame to a SQL table within the SQLite database
209
  df2.to_sql('housing_data_sql', con=engine, if_exists='replace', index=False)