Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from flask import Flask, render_template, request, redirect, url_for
|
2 |
from flask_socketio import SocketIO
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
@@ -114,7 +114,8 @@ def create_agent_app(db_path: str):
|
|
114 |
workflow.add_node("first_tool_call", first_tool_call)
|
115 |
workflow.add_node("list_tables_tool", create_tool_node_with_fallback([list_tool]))
|
116 |
workflow.add_node("get_schema_tool", create_tool_node_with_fallback([schema_tool]))
|
117 |
-
|
|
|
118 |
workflow.add_node("query_gen", query_gen_node)
|
119 |
workflow.add_node("correct_query", model_check_query)
|
120 |
workflow.add_node("execute_query", create_tool_node_with_fallback([db_query_tool]))
|
@@ -148,7 +149,7 @@ def upload():
|
|
148 |
save_path = os.path.join(flask_app.config['UPLOAD_FOLDER'], "uploaded.db")
|
149 |
file.save(save_path)
|
150 |
abs_file_path = os.path.abspath(save_path)
|
151 |
-
agent_app = None
|
152 |
socketio.emit("log", {"message": f"Database '{filename}' uploaded."})
|
153 |
return redirect(url_for("index"))
|
154 |
return render_template("upload.html")
|
@@ -185,7 +186,8 @@ def run_agent(prompt):
|
|
185 |
socketio.emit("log", {"message": f"[ERROR]: {str(e)}"})
|
186 |
socketio.emit("final", {"message": "Generation failed."})
|
187 |
|
|
|
188 |
app = flask_app
|
189 |
|
190 |
if __name__ == "__main__":
|
191 |
-
socketio.run(app, debug=True)
|
|
|
1 |
+
from flask import Flask, render_template, request, redirect, url_for, flash
|
2 |
from flask_socketio import SocketIO
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
|
|
114 |
workflow.add_node("first_tool_call", first_tool_call)
|
115 |
workflow.add_node("list_tables_tool", create_tool_node_with_fallback([list_tool]))
|
116 |
workflow.add_node("get_schema_tool", create_tool_node_with_fallback([schema_tool]))
|
117 |
+
# Corrected the unterminated string literal in the lambda function below:
|
118 |
+
workflow.add_node("model_get_schema", lambda s: {"messages": [model_get_schema.invoke(s["messages"])]})
|
119 |
workflow.add_node("query_gen", query_gen_node)
|
120 |
workflow.add_node("correct_query", model_check_query)
|
121 |
workflow.add_node("execute_query", create_tool_node_with_fallback([db_query_tool]))
|
|
|
149 |
save_path = os.path.join(flask_app.config['UPLOAD_FOLDER'], "uploaded.db")
|
150 |
file.save(save_path)
|
151 |
abs_file_path = os.path.abspath(save_path)
|
152 |
+
agent_app = None # Reset agent; reinitialize on next query.
|
153 |
socketio.emit("log", {"message": f"Database '{filename}' uploaded."})
|
154 |
return redirect(url_for("index"))
|
155 |
return render_template("upload.html")
|
|
|
186 |
socketio.emit("log", {"message": f"[ERROR]: {str(e)}"})
|
187 |
socketio.emit("final", {"message": "Generation failed."})
|
188 |
|
189 |
+
# Expose the Flask app as "app" for Gunicorn
|
190 |
app = flask_app
|
191 |
|
192 |
if __name__ == "__main__":
|
193 |
+
socketio.run(app, debug=True)
|