Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -194,6 +194,32 @@ agent_app = workflow.compile()
|
|
194 |
flask_app = Flask(__name__)
|
195 |
socketio = SocketIO(flask_app, cors_allowed_origins="*")
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
# Function to run the agent in a separate thread
|
198 |
def run_agent(prompt):
|
199 |
try:
|
@@ -205,7 +231,7 @@ def run_agent(prompt):
|
|
205 |
except Exception as e:
|
206 |
socketio.emit("log", {"message": f"[ERROR]: {str(e)}"})
|
207 |
socketio.emit("final", {"message": "Generation failed."})
|
208 |
-
|
209 |
@flask_app.route("/")
|
210 |
def index():
|
211 |
return render_template("index.html")
|
@@ -220,5 +246,8 @@ def generate():
|
|
220 |
thread.start()
|
221 |
return "OK", 200
|
222 |
|
|
|
|
|
|
|
223 |
if __name__ == "__main__":
|
224 |
socketio.run(app, debug=True)
|
|
|
194 |
flask_app = Flask(__name__)
|
195 |
socketio = SocketIO(flask_app, cors_allowed_origins="*")
|
196 |
|
197 |
+
# Set up an uploads directory
|
198 |
+
UPLOAD_FOLDER = os.path.join(os.getcwd(), "uploads")
|
199 |
+
if not os.path.exists(UPLOAD_FOLDER):
|
200 |
+
os.makedirs(UPLOAD_FOLDER)
|
201 |
+
|
202 |
+
# Create a global agent_app using the default DATABASE_URI
|
203 |
+
agent_app = create_agent_app(DATABASE_URI)
|
204 |
+
|
205 |
+
# Endpoint for uploading a DB file
|
206 |
+
@flask_app.route("/upload", methods=["GET", "POST"])
|
207 |
+
def upload():
|
208 |
+
if request.method == "POST":
|
209 |
+
file = request.files.get("file")
|
210 |
+
if not file:
|
211 |
+
return "No file uploaded", 400
|
212 |
+
file_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
213 |
+
file.save(file_path)
|
214 |
+
# Build a new URI (for SQLite, use absolute path)
|
215 |
+
new_db_uri = f"sqlite:///{file_path}"
|
216 |
+
# Reinitialize the agent_app with the new DB
|
217 |
+
global agent_app
|
218 |
+
agent_app = create_agent_app(new_db_uri)
|
219 |
+
socketio.emit("log", {"message": f"[INFO]: Database file '{file.filename}' uploaded and loaded."})
|
220 |
+
return redirect(url_for("index"))
|
221 |
+
return render_template("upload.html")
|
222 |
+
|
223 |
# Function to run the agent in a separate thread
|
224 |
def run_agent(prompt):
|
225 |
try:
|
|
|
231 |
except Exception as e:
|
232 |
socketio.emit("log", {"message": f"[ERROR]: {str(e)}"})
|
233 |
socketio.emit("final", {"message": "Generation failed."})
|
234 |
+
|
235 |
@flask_app.route("/")
|
236 |
def index():
|
237 |
return render_template("index.html")
|
|
|
246 |
thread.start()
|
247 |
return "OK", 200
|
248 |
|
249 |
+
# Assign the Flask app to "app" for gunicorn
|
250 |
+
app = flask_app
|
251 |
+
|
252 |
if __name__ == "__main__":
|
253 |
socketio.run(app, debug=True)
|