Spaces:
Runtime error
Runtime error
Update app.py
Browse files50 unmodified lines5152535455545556575859605961626364656667686970717273177 unmodified lines25125225324724825425525025625725825950 unmodified linestools = toolkit.get_tools()
def create_agent_app(db_uri: str): # Create new SQLDatabase connectiondef 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 SQLDatabase db_instance = SQLDatabase.from_uri(db_uri)
# Create SQL toolkit and get the tools # Create SQL toolkit and get the tools. from langchain_community.agent_toolkits import SQLDatabaseToolkit toolkit_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 lines return "No file uploaded", 400 file_path = os.path.join(UPLOAD_FOLDER, file.filename) file.save(file_path) # For SQLite, use the absolute file path in the URI new_db_uri = f"sqlite:///{file_path}" # Reinitialize the agent_app using the uploaded file's path. global agent_app agent_app = create_agent_app(new_db_uri) agent_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