WebashalarForML commited on
Commit
da1e0d4
·
verified ·
1 Parent(s): b129b7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -229,12 +229,17 @@ def create_app():
229
  os.makedirs(UPLOAD_FOLDER)
230
 
231
  flask_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
232
-
233
  # Create a global agent_app using the default DATABASE_URI
234
  ###############################################################################
235
  # Helper function to run the agent; uses the global agent_app.
236
  ###############################################################################
237
  def run_agent(prompt, socketio):
 
 
 
 
 
238
  try:
239
  query = {"messages": [("user", prompt)]}
240
  result = agent_app.invoke(query)
@@ -278,7 +283,7 @@ def create_app():
278
  if file and file.filename.endswith('.db'):
279
  # Use flask_app.config instead of app.config
280
  db_path = os.path.join(flask_app.config['UPLOAD_FOLDER'], 'uploaded.db')
281
- print("file uploaded")
282
  file.save(db_path)
283
 
284
  # Convert the file path to an absolute path and reinitialize the agent_app
@@ -286,10 +291,8 @@ def create_app():
286
  global agent_app
287
  agent_app = create_agent_app(abs_file_path)
288
 
289
- # Use an f-string properly to log the uploaded file name
290
  print(f"[INFO_PRINT]: Database file '{file.filename}' uploaded and loaded.")
291
  socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
292
- print("Received file:", file.filename)
293
  return redirect(url_for("index")) # Go back to index page
294
  # For GET requests, simply render the upload form.
295
  return render_template("upload.html")
 
229
  os.makedirs(UPLOAD_FOLDER)
230
 
231
  flask_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
232
+ agent_app = None
233
  # Create a global agent_app using the default DATABASE_URI
234
  ###############################################################################
235
  # Helper function to run the agent; uses the global agent_app.
236
  ###############################################################################
237
  def run_agent(prompt, socketio):
238
+ global agent_app
239
+ if agent_app is None:
240
+ socketio.emit("log", {"message": "[ERROR]: No database has been uploaded. Please upload a database file first."})
241
+ socketio.emit("final", {"message": "No database available. Upload a database and try again."})
242
+ return
243
  try:
244
  query = {"messages": [("user", prompt)]}
245
  result = agent_app.invoke(query)
 
283
  if file and file.filename.endswith('.db'):
284
  # Use flask_app.config instead of app.config
285
  db_path = os.path.join(flask_app.config['UPLOAD_FOLDER'], 'uploaded.db')
286
+ print("Saving file to:", db_path)
287
  file.save(db_path)
288
 
289
  # Convert the file path to an absolute path and reinitialize the agent_app
 
291
  global agent_app
292
  agent_app = create_agent_app(abs_file_path)
293
 
 
294
  print(f"[INFO_PRINT]: Database file '{file.filename}' uploaded and loaded.")
295
  socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
 
296
  return redirect(url_for("index")) # Go back to index page
297
  # For GET requests, simply render the upload form.
298
  return render_template("upload.html")