diff --git a/app/app.py b/app/app.py index bf807a6..b45a4ef 100644 --- a/app/app.py +++ b/app/app.py @@ -862,7 +862,7 @@ def vision(cid): # =========== # IO -from io_excel import convert_excel +from io.excel import convert_excel, convert_excel_all_sheets @app.route("/api/import_excel/", methods=["POST"]) @login_required @@ -878,20 +878,28 @@ def import_excel(cid): temp_path = f"/data/{uuid.uuid4()}.{ext}" file.save(temp_path) - tsv = convert_excel(temp_path) + # tsv = convert_excel(temp_path) + # Convert all sheets + sheets = convert_excel_all_sheets(temp_path) + db = SessionLocal() - msg = Message( - id=str(uuid.uuid4()), - conversation_id=cid, - role="user", - content=f"```\n{tsv}\n```" - ) - db.add(msg) - db.commit() - db.close() + # Each sheet becomes a separate TSV message + for sheet_name, tsv in sheets.items(): + msg = Message( + id=str(uuid.uuid4()), + conversation_id=cid, + role="user", + content=f"### Sheet: {sheet_name}\n```\n{tsv}\n```" + ) + db.add(msg) + + # return jsonify({"status": "ok"}) + return jsonify({"status": "ok", "sheets": list(sheets.keys())}) + + + - return jsonify({"status": "ok"}) # ================