WebashalarForML commited on
Commit
6e0b574
·
verified ·
1 Parent(s): df480e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -31
app.py CHANGED
@@ -250,40 +250,47 @@ def create_app():
250
 
251
  @flask_app.route("/generate", methods=["POST"])
252
  def generate():
253
- socketio.emit("log", {"message": "[STEP]: Entering query_gen..."})
254
- data = request.json
255
- prompt = data.get("prompt", "")
256
- socketio.emit("log", {"message": f"[INFO]: Received prompt: {prompt}\n"})
257
- # Run the agent in a separate thread
258
- thread = threading.Thread(target=run_agent, args=(prompt, socketio))
259
- thread.start()
260
- return "OK", 200
 
 
 
261
 
262
  @flask_app.route("/upload", methods=["POST", "GET"])
263
  def upload():
264
- if request.method == 'POST':
265
- file = request.files.get('file')
266
- if not file:
267
- print("No file uploaded")
268
- return "No file uploaded", 400
269
- if file and file.filename.endswith('.db'):
270
- # Use flask_app.config instead of app.config
271
- db_path = os.path.join(flask_app.config['UPLOAD_FOLDER'], 'uploaded.db')
272
- print("file uploaded")
273
- file.save(db_path)
274
-
275
- # Convert the file path to an absolute path and reinitialize the agent_app
276
- abs_file_path = os.path.abspath(db_path)
277
- global agent_app
278
- agent_app = create_agent_app(abs_file_path)
279
-
280
- # Use an f-string properly to log the uploaded file name
281
- print(f"[INFO_PRINT]: Database file '{file.filename}' uploaded and loaded.")
282
- socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
283
- print("Received file:", file.filename)
284
- return redirect(url_for("index")) # Go back to index page
285
- # For GET requests, simply render the upload form.
286
- return render_template("upload.html")
 
 
 
 
287
 
288
  return flask_app, socketio
289
 
 
250
 
251
  @flask_app.route("/generate", methods=["POST"])
252
  def generate():
253
+ try:
254
+ socketio.emit("log", {"message": "[STEP]: Entering query_gen..."})
255
+ data = request.json
256
+ prompt = data.get("prompt", "")
257
+ socketio.emit("log", {"message": f"[INFO]: Received prompt: {prompt}\n"})
258
+ # Run the agent in a separate thread
259
+ thread = threading.Thread(target=run_agent, args=(prompt, socketio))
260
+ thread.start()
261
+ return "OK", 200
262
+ except Exception as e:
263
+ socketio.emit("log", {"message": f"[ERROR]: {str(e)}"})
264
 
265
  @flask_app.route("/upload", methods=["POST", "GET"])
266
  def upload():
267
+ try:
268
+ if request.method == 'POST':
269
+ file = request.files.get('file')
270
+ if not file:
271
+ print("No file uploaded")
272
+ return "No file uploaded", 400
273
+ if file and file.filename.endswith('.db'):
274
+ # Use flask_app.config instead of app.config
275
+ db_path = os.path.join(flask_app.config['UPLOAD_FOLDER'], 'uploaded.db')
276
+ print("file uploaded")
277
+ file.save(db_path)
278
+
279
+ # Convert the file path to an absolute path and reinitialize the agent_app
280
+ abs_file_path = os.path.abspath(db_path)
281
+ global agent_app
282
+ agent_app = create_agent_app(abs_file_path)
283
+
284
+ # Use an f-string properly to log the uploaded file name
285
+ print(f"[INFO_PRINT]: Database file '{file.filename}' uploaded and loaded.")
286
+ socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
287
+ print("Received file:", file.filename)
288
+ return redirect(url_for("index")) # Go back to index page
289
+ # For GET requests, simply render the upload form.
290
+ return render_template("upload.html")
291
+ except Exception as e:
292
+ socketio.emit("log", {"message": f"[ERROR]: {str(e)}"})
293
+ return render_template("upload.html")
294
 
295
  return flask_app, socketio
296