WebashalarForML commited on
Commit
5109e18
·
verified ·
1 Parent(s): f648e72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -51,16 +51,23 @@ toolkit = SQLDatabaseToolkit(db=db, llm=llm)
51
  tools = toolkit.get_tools()
52
 
53
 
54
- def create_agent_app(db_uri: str):
55
- # Create new SQLDatabase connection
 
 
56
  from langchain_community.utilities import SQLDatabase
57
  db_instance = SQLDatabase.from_uri(db_uri)
58
 
59
- # Create SQL toolkit and get the tools
60
  from langchain_community.agent_toolkits import SQLDatabaseToolkit
61
  toolkit_instance = SQLDatabaseToolkit(db=db_instance, llm=llm)
62
  tools_instance = toolkit_instance.get_tools()
63
 
 
 
 
 
 
64
  # Define a custom query tool for executing SQL queries
65
 
66
  # Define a custom query tool for executing SQL queries
@@ -244,10 +251,9 @@ def create_app():
244
  return "No file uploaded", 400
245
  file_path = os.path.join(UPLOAD_FOLDER, file.filename)
246
  file.save(file_path)
247
- # For SQLite, use the absolute file path in the URI
248
- new_db_uri = f"sqlite:///{file_path}"
249
  global agent_app
250
- agent_app = create_agent_app(new_db_uri)
251
  socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
252
  return redirect(url_for("index"))
253
  return render_template("upload.html")
 
51
  tools = toolkit.get_tools()
52
 
53
 
54
+ def create_agent_app(db_path: str):
55
+ # Construct the SQLite URI from the given file path.
56
+ db_uri = f"sqlite:///{db_path}"
57
+ # Create new SQLDatabase connection using the constructed URI.
58
  from langchain_community.utilities import SQLDatabase
59
  db_instance = SQLDatabase.from_uri(db_uri)
60
 
61
+ # Create SQL toolkit and get the tools.
62
  from langchain_community.agent_toolkits import SQLDatabaseToolkit
63
  toolkit_instance = SQLDatabaseToolkit(db=db_instance, llm=llm)
64
  tools_instance = toolkit_instance.get_tools()
65
 
66
+ # ... (rest of the logic remains unchanged)
67
+ # [Define custom query tool, prompt templates, workflow nodes, etc.]
68
+
69
+ # Compile and return the agent application workflow.
70
+ return workflow.compile()
71
  # Define a custom query tool for executing SQL queries
72
 
73
  # Define a custom query tool for executing SQL queries
 
251
  return "No file uploaded", 400
252
  file_path = os.path.join(UPLOAD_FOLDER, file.filename)
253
  file.save(file_path)
254
+ # Reinitialize the agent_app using the uploaded file's path.
 
255
  global agent_app
256
+ agent_app = create_agent_app(file_path)
257
  socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
258
  return redirect(url_for("index"))
259
  return render_template("upload.html")