Spaces:
Runtime error
Runtime error
Update app.py
Browse files50 unmodified lines51525354555657585960616263646566177 unmodified lines24424524624724824925025125225350 unmodified linestools = toolkit.get_tools()def create_agent_app(db_uri: str):# Create new SQLDatabase connectionfrom langchain_community.utilities import SQLDatabasedb_instance = SQLDatabase.from_uri(db_uri)# Create SQL toolkit and get the toolsfrom langchain_community.agent_toolkits import SQLDatabaseToolkittoolkit_instance = SQLDatabaseToolkit(db=db_instance, llm=llm)tools_instance = toolkit_instance.get_tools()# Define a custom query tool for executing SQL queries# Define a custom query tool for executing SQL queries177 unmodified linesreturn "No file uploaded", 400file_path = os.path.join(UPLOAD_FOLDER, file.filename)file.save(file_path)# For SQLite, use the absolute file path in the URInew_db_uri = f"sqlite:///{file_path}"global agent_appagent_app = create_agent_app(new_db_uri)socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})return redirect(url_for("index"))return render_template("upload.html")50 unmodified lines5152535455565758596061626364656667686970717273177 unmodified lines25125225325425525625725825950 unmodified linestools = toolkit.get_tools()def create_agent_app(db_path: str):# Construct the SQLite URI from the given file path.db_uri = f"sqlite:///{db_path}"# Create new SQLDatabase connection using the constructed URI.from langchain_community.utilities import SQLDatabasedb_instance = SQLDatabase.from_uri(db_uri)# Create SQL toolkit and get the tools.from langchain_community.agent_toolkits import SQLDatabaseToolkittoolkit_instance = SQLDatabaseToolkit(db=db_instance, llm=llm)tools_instance = toolkit_instance.get_tools()# ... (rest of the logic remains unchanged)# [Define custom query tool, prompt templates, workflow nodes, etc.]# Compile and return the agent application workflow.return workflow.compile()# Define a custom query tool for executing SQL queries# Define a custom query tool for executing SQL queries177 unmodified linesreturn "No file uploaded", 400file_path = os.path.join(UPLOAD_FOLDER, file.filename)file.save(file_path)# Reinitialize the agent_app using the uploaded file's path.global agent_appagent_app = create_agent_app(file_path)socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})return redirect(url_for("index"))return render_template("upload.html")
app.py+12-6