WebashalarForML commited on
Commit
ad4f466
·
verified ·
1 Parent(s): 9fddf83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -22
app.py CHANGED
@@ -207,25 +207,7 @@ def create_agent_app(db_path: str):
207
  # Compile and return the agent application workflow.
208
  return workflow.compile()
209
 
210
- ###############################################################################
211
- # Helper function to run the agent; uses the global agent_app.
212
- ###############################################################################
213
- def run_agent(prompt, socketio):
214
- try:
215
- query = {"messages": [("user", prompt)]}
216
- result = agent_app.invoke(query)
217
- try:
218
- result = result["messages"][-1].tool_calls[0]["args"]["final_answer"]
219
- except Exception:
220
- result = "Query failed or no valid answer found."
221
-
222
- print("final_answer------>", result)
223
- socketio.emit("final", {"message": f"{result}"})
224
- except Exception as e:
225
- socketio.emit("log", {"message": f"[ERROR]: {str(e)}"})
226
- socketio.emit("final", {"message": "Generation failed."})
227
-
228
- ###############################################################################
229
  # Application Factory: create_app()
230
  #
231
  # This function sets up the Flask application, SocketIO, routes, and initializes
@@ -243,8 +225,23 @@ def create_app():
243
  flask_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
244
 
245
  # Create a global agent_app using the default DATABASE_URI
246
- #global agent_app
247
- #agent_app = create_agent_app(DATABASE_URI)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
  @flask_app.route("/")
250
  def index():
@@ -276,7 +273,8 @@ def create_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
  socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
281
  return redirect(url_for("index")) # Go back to index page
282
  return render_template("upload.html")
 
207
  # Compile and return the agent application workflow.
208
  return workflow.compile()
209
 
210
+ ###############################################################################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  # Application Factory: create_app()
212
  #
213
  # This function sets up the Flask application, SocketIO, routes, and initializes
 
225
  flask_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
226
 
227
  # Create a global agent_app using the default DATABASE_URI
228
+ ###############################################################################
229
+ # Helper function to run the agent; uses the global agent_app.
230
+ ###############################################################################
231
+ def run_agent(prompt, socketio):
232
+ try:
233
+ query = {"messages": [("user", prompt)]}
234
+ result = agent_app.invoke(query)
235
+ try:
236
+ result = result["messages"][-1].tool_calls[0]["args"]["final_answer"]
237
+ except Exception:
238
+ result = "Query failed or no valid answer found."
239
+
240
+ print("final_answer------>", result)
241
+ socketio.emit("final", {"message": f"{result}"})
242
+ except Exception as e:
243
+ socketio.emit("log", {"message": f"[ERROR]: {str(e)}"})
244
+ socketio.emit("final", {"message": "Generation failed."})
245
 
246
  @flask_app.route("/")
247
  def index():
 
273
  abs_file_path = os.path.abspath(db_path)
274
  global agent_app
275
  agent_app = create_agent_app(abs_file_path)
276
+ print("agent app",agent_app)
277
+ print("[INFO_PRINT]: Database file '{file.filename}' uploaded and loaded.")
278
  socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
279
  return redirect(url_for("index")) # Go back to index page
280
  return render_template("upload.html")