Spaces:
Running
Running
Commit ·
cade43f
1
Parent(s): 75dfb75
aligned uploader and agent path
Browse files- streamlit-client/app.py +81 -20
streamlit-client/app.py
CHANGED
|
@@ -135,15 +135,28 @@ def run_ideation(q):
|
|
| 135 |
|
| 136 |
|
| 137 |
def run_data(path, q):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
w = DataWorkflow(
|
| 139 |
-
data_path=
|
| 140 |
workspace_path=st.session_state.workspace_path,
|
| 141 |
recursion_limit=100,
|
| 142 |
)
|
| 143 |
w.run()
|
| 144 |
intermediate_state = getattr(w, "data_agent_intermediate_state", [])
|
| 145 |
if w.final_status != "success":
|
| 146 |
-
|
|
|
|
| 147 |
out = ["## Data Analysis Complete"]
|
| 148 |
if w.data_summary:
|
| 149 |
out.append(w.data_summary)
|
|
@@ -152,10 +165,19 @@ def run_data(path, q):
|
|
| 152 |
|
| 153 |
def run_experiment(q, path):
|
| 154 |
if path:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
w = ExperimentWorkflow.from_data_analysis_file(
|
| 156 |
workspace_path=st.session_state.workspace_path,
|
| 157 |
user_query=q,
|
| 158 |
-
data_analysis_path=
|
| 159 |
max_revisions=5,
|
| 160 |
recursion_limit=100,
|
| 161 |
)
|
|
@@ -166,10 +188,23 @@ def run_experiment(q, path):
|
|
| 166 |
|
| 167 |
|
| 168 |
def run_full(cfg):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
w = FullWorkflowWithIdeation(
|
| 170 |
user_query=cfg["query"],
|
| 171 |
workspace_path=st.session_state.workspace_path,
|
| 172 |
-
data_path=
|
| 173 |
run_data_workflow=cfg["run_data"],
|
| 174 |
run_experiment_workflow=cfg["run_exp"],
|
| 175 |
max_revisions=5,
|
|
@@ -203,11 +238,12 @@ def save_and_extract_upload(uploaded_file) -> Path | None:
|
|
| 203 |
with open(zip_path, "wb") as f:
|
| 204 |
f.write(uploaded_file.getvalue())
|
| 205 |
extract_dir = dest_dir / "extracted"
|
| 206 |
-
extract_dir.mkdir(exist_ok=True)
|
| 207 |
with zipfile.ZipFile(zip_path, "r") as zf:
|
| 208 |
zf.extractall(extract_dir)
|
| 209 |
zip_path.unlink()
|
| 210 |
-
|
|
|
|
| 211 |
|
| 212 |
|
| 213 |
def find_data_analysis_file(extract_dir: Path) -> Path | None:
|
|
@@ -444,24 +480,33 @@ elif st.session_state.selected_workflow == "data":
|
|
| 444 |
if uploaded_zip:
|
| 445 |
cleanup_uploaded_data() # Remove previous upload before saving new one
|
| 446 |
extracted = save_and_extract_upload(uploaded_zip)
|
| 447 |
-
if extracted:
|
|
|
|
|
|
|
| 448 |
st.session_state.uploaded_data_path = str(extracted)
|
| 449 |
st.session_state.workspace_path = extracted.parent
|
| 450 |
path_to_use = str(extracted)
|
|
|
|
| 451 |
else:
|
| 452 |
-
st.error("Failed to process uploaded zip file.")
|
| 453 |
elif data_path_manual.strip():
|
| 454 |
path_to_use = data_path_manual.strip()
|
| 455 |
elif st.session_state.get("uploaded_data_path"):
|
| 456 |
-
path = Path(st.session_state.uploaded_data_path)
|
| 457 |
if path.exists():
|
| 458 |
-
path_to_use =
|
| 459 |
st.session_state.workspace_path = path.parent
|
| 460 |
else:
|
|
|
|
| 461 |
cleanup_uploaded_data()
|
| 462 |
if path_to_use:
|
| 463 |
-
|
| 464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
else:
|
| 466 |
st.error("Please upload a zip file or enter a data path.")
|
| 467 |
|
|
@@ -492,22 +537,30 @@ elif st.session_state.selected_workflow == "experiment":
|
|
| 492 |
if "uploaded_experiment_path" in st.session_state:
|
| 493 |
del st.session_state.uploaded_experiment_path
|
| 494 |
extracted = save_and_extract_upload(uploaded_exp_zip)
|
| 495 |
-
if extracted:
|
|
|
|
| 496 |
analysis_file = find_data_analysis_file(extracted)
|
| 497 |
-
if analysis_file:
|
|
|
|
| 498 |
st.session_state.uploaded_experiment_path = str(analysis_file)
|
| 499 |
st.session_state.workspace_path = analysis_file.parent
|
| 500 |
path_to_use = str(analysis_file)
|
|
|
|
| 501 |
else:
|
| 502 |
-
st.error(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
elif data_path_manual.strip():
|
| 504 |
path_to_use = data_path_manual.strip()
|
| 505 |
elif st.session_state.get("uploaded_experiment_path"):
|
| 506 |
-
p = Path(st.session_state.uploaded_experiment_path)
|
| 507 |
if p.exists():
|
| 508 |
-
path_to_use =
|
| 509 |
st.session_state.workspace_path = p.parent
|
| 510 |
else:
|
|
|
|
| 511 |
if "uploaded_experiment_path" in st.session_state:
|
| 512 |
del st.session_state.uploaded_experiment_path
|
| 513 |
if path_to_use:
|
|
@@ -546,18 +599,26 @@ elif st.session_state.selected_workflow == "full":
|
|
| 546 |
if "uploaded_full_data_path" in st.session_state:
|
| 547 |
del st.session_state.uploaded_full_data_path
|
| 548 |
extracted = save_and_extract_upload(uploaded_full_zip)
|
| 549 |
-
if extracted:
|
|
|
|
| 550 |
st.session_state.uploaded_full_data_path = str(extracted)
|
| 551 |
st.session_state.workspace_path = extracted.parent
|
| 552 |
data_path_to_use = str(extracted)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
elif data_path_manual.strip():
|
| 554 |
data_path_to_use = data_path_manual.strip()
|
| 555 |
elif st.session_state.get("uploaded_full_data_path"):
|
| 556 |
-
p = Path(st.session_state.uploaded_full_data_path)
|
| 557 |
if p.exists():
|
| 558 |
-
data_path_to_use =
|
| 559 |
st.session_state.workspace_path = p.parent
|
| 560 |
else:
|
|
|
|
| 561 |
if "uploaded_full_data_path" in st.session_state:
|
| 562 |
del st.session_state.uploaded_full_data_path
|
| 563 |
if not data_path_to_use:
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
def run_data(path, q):
|
| 138 |
+
# Ensure path is absolute and exists
|
| 139 |
+
data_path = Path(path).resolve()
|
| 140 |
+
if not data_path.exists():
|
| 141 |
+
return f"Error: Data path does not exist: {data_path}", []
|
| 142 |
+
|
| 143 |
+
# Log path for debugging
|
| 144 |
+
logger = __import__("loguru").logger
|
| 145 |
+
logger.info(f"Running data analysis on path: {data_path}")
|
| 146 |
+
logger.info(
|
| 147 |
+
f"Path exists: {data_path.exists()}, is_dir: {data_path.is_dir()}, is_file: {data_path.is_file()}"
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
w = DataWorkflow(
|
| 151 |
+
data_path=data_path,
|
| 152 |
workspace_path=st.session_state.workspace_path,
|
| 153 |
recursion_limit=100,
|
| 154 |
)
|
| 155 |
w.run()
|
| 156 |
intermediate_state = getattr(w, "data_agent_intermediate_state", [])
|
| 157 |
if w.final_status != "success":
|
| 158 |
+
error_msg = w.error_message or "Data workflow failed"
|
| 159 |
+
return f"Data workflow failed: {error_msg}", intermediate_state
|
| 160 |
out = ["## Data Analysis Complete"]
|
| 161 |
if w.data_summary:
|
| 162 |
out.append(w.data_summary)
|
|
|
|
| 165 |
|
| 166 |
def run_experiment(q, path):
|
| 167 |
if path:
|
| 168 |
+
# Ensure path is absolute and exists
|
| 169 |
+
analysis_path = Path(path).resolve()
|
| 170 |
+
if not analysis_path.exists():
|
| 171 |
+
return f"Error: Data analysis file does not exist: {analysis_path}", []
|
| 172 |
+
|
| 173 |
+
logger = __import__("loguru").logger
|
| 174 |
+
logger.info(f"Running experiment with analysis file: {analysis_path}")
|
| 175 |
+
logger.info(f"Path exists: {analysis_path.exists()}, is_file: {analysis_path.is_file()}")
|
| 176 |
+
|
| 177 |
w = ExperimentWorkflow.from_data_analysis_file(
|
| 178 |
workspace_path=st.session_state.workspace_path,
|
| 179 |
user_query=q,
|
| 180 |
+
data_analysis_path=str(analysis_path),
|
| 181 |
max_revisions=5,
|
| 182 |
recursion_limit=100,
|
| 183 |
)
|
|
|
|
| 188 |
|
| 189 |
|
| 190 |
def run_full(cfg):
|
| 191 |
+
data_path = None
|
| 192 |
+
if cfg.get("data_path"):
|
| 193 |
+
data_path = Path(cfg["data_path"]).resolve()
|
| 194 |
+
if not data_path.exists():
|
| 195 |
+
return f"Error: Data path does not exist: {data_path}", []
|
| 196 |
+
|
| 197 |
+
logger = __import__("loguru").logger
|
| 198 |
+
if data_path:
|
| 199 |
+
logger.info(f"Running full workflow with data path: {data_path}")
|
| 200 |
+
logger.info(
|
| 201 |
+
f"Path exists: {data_path.exists()}, is_dir: {data_path.is_dir()}, is_file: {data_path.is_file()}"
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
w = FullWorkflowWithIdeation(
|
| 205 |
user_query=cfg["query"],
|
| 206 |
workspace_path=st.session_state.workspace_path,
|
| 207 |
+
data_path=data_path,
|
| 208 |
run_data_workflow=cfg["run_data"],
|
| 209 |
run_experiment_workflow=cfg["run_exp"],
|
| 210 |
max_revisions=5,
|
|
|
|
| 238 |
with open(zip_path, "wb") as f:
|
| 239 |
f.write(uploaded_file.getvalue())
|
| 240 |
extract_dir = dest_dir / "extracted"
|
| 241 |
+
extract_dir.mkdir(parents=True, exist_ok=True)
|
| 242 |
with zipfile.ZipFile(zip_path, "r") as zf:
|
| 243 |
zf.extractall(extract_dir)
|
| 244 |
zip_path.unlink()
|
| 245 |
+
# Return absolute path to ensure it works in container environments
|
| 246 |
+
return extract_dir.resolve()
|
| 247 |
|
| 248 |
|
| 249 |
def find_data_analysis_file(extract_dir: Path) -> Path | None:
|
|
|
|
| 480 |
if uploaded_zip:
|
| 481 |
cleanup_uploaded_data() # Remove previous upload before saving new one
|
| 482 |
extracted = save_and_extract_upload(uploaded_zip)
|
| 483 |
+
if extracted and extracted.exists():
|
| 484 |
+
# Use absolute path and verify it exists
|
| 485 |
+
extracted = extracted.resolve()
|
| 486 |
st.session_state.uploaded_data_path = str(extracted)
|
| 487 |
st.session_state.workspace_path = extracted.parent
|
| 488 |
path_to_use = str(extracted)
|
| 489 |
+
st.success(f"✅ File uploaded and extracted to: {path_to_use}")
|
| 490 |
else:
|
| 491 |
+
st.error(f"Failed to process uploaded zip file. Extracted path: {extracted}")
|
| 492 |
elif data_path_manual.strip():
|
| 493 |
path_to_use = data_path_manual.strip()
|
| 494 |
elif st.session_state.get("uploaded_data_path"):
|
| 495 |
+
path = Path(st.session_state.uploaded_data_path).resolve()
|
| 496 |
if path.exists():
|
| 497 |
+
path_to_use = str(path)
|
| 498 |
st.session_state.workspace_path = path.parent
|
| 499 |
else:
|
| 500 |
+
st.warning(f"Previously uploaded path no longer exists: {path}")
|
| 501 |
cleanup_uploaded_data()
|
| 502 |
if path_to_use:
|
| 503 |
+
# Verify path exists before creating workflow config
|
| 504 |
+
verify_path = Path(path_to_use).resolve()
|
| 505 |
+
if not verify_path.exists():
|
| 506 |
+
st.error(f"Path does not exist: {path_to_use}")
|
| 507 |
+
else:
|
| 508 |
+
workflow_config = {"type": "data", "path": str(verify_path), "query": query}
|
| 509 |
+
st.session_state.selected_workflow = None
|
| 510 |
else:
|
| 511 |
st.error("Please upload a zip file or enter a data path.")
|
| 512 |
|
|
|
|
| 537 |
if "uploaded_experiment_path" in st.session_state:
|
| 538 |
del st.session_state.uploaded_experiment_path
|
| 539 |
extracted = save_and_extract_upload(uploaded_exp_zip)
|
| 540 |
+
if extracted and extracted.exists():
|
| 541 |
+
extracted = extracted.resolve()
|
| 542 |
analysis_file = find_data_analysis_file(extracted)
|
| 543 |
+
if analysis_file and analysis_file.exists():
|
| 544 |
+
analysis_file = analysis_file.resolve()
|
| 545 |
st.session_state.uploaded_experiment_path = str(analysis_file)
|
| 546 |
st.session_state.workspace_path = analysis_file.parent
|
| 547 |
path_to_use = str(analysis_file)
|
| 548 |
+
st.success(f"✅ Found analysis file: {path_to_use}")
|
| 549 |
else:
|
| 550 |
+
st.error(
|
| 551 |
+
f"Zip must contain data_analysis.md or analysis.md. Searched in: {extracted}"
|
| 552 |
+
)
|
| 553 |
+
else:
|
| 554 |
+
st.error(f"Failed to process uploaded zip file. Extracted path: {extracted}")
|
| 555 |
elif data_path_manual.strip():
|
| 556 |
path_to_use = data_path_manual.strip()
|
| 557 |
elif st.session_state.get("uploaded_experiment_path"):
|
| 558 |
+
p = Path(st.session_state.uploaded_experiment_path).resolve()
|
| 559 |
if p.exists():
|
| 560 |
+
path_to_use = str(p)
|
| 561 |
st.session_state.workspace_path = p.parent
|
| 562 |
else:
|
| 563 |
+
st.warning(f"Previously uploaded path no longer exists: {p}")
|
| 564 |
if "uploaded_experiment_path" in st.session_state:
|
| 565 |
del st.session_state.uploaded_experiment_path
|
| 566 |
if path_to_use:
|
|
|
|
| 599 |
if "uploaded_full_data_path" in st.session_state:
|
| 600 |
del st.session_state.uploaded_full_data_path
|
| 601 |
extracted = save_and_extract_upload(uploaded_full_zip)
|
| 602 |
+
if extracted and extracted.exists():
|
| 603 |
+
extracted = extracted.resolve()
|
| 604 |
st.session_state.uploaded_full_data_path = str(extracted)
|
| 605 |
st.session_state.workspace_path = extracted.parent
|
| 606 |
data_path_to_use = str(extracted)
|
| 607 |
+
st.success(f"✅ File uploaded and extracted to: {data_path_to_use}")
|
| 608 |
+
else:
|
| 609 |
+
st.error(
|
| 610 |
+
f"Failed to process uploaded zip file. Extracted path: {extracted}"
|
| 611 |
+
)
|
| 612 |
+
data_path_to_use = None
|
| 613 |
elif data_path_manual.strip():
|
| 614 |
data_path_to_use = data_path_manual.strip()
|
| 615 |
elif st.session_state.get("uploaded_full_data_path"):
|
| 616 |
+
p = Path(st.session_state.uploaded_full_data_path).resolve()
|
| 617 |
if p.exists():
|
| 618 |
+
data_path_to_use = str(p)
|
| 619 |
st.session_state.workspace_path = p.parent
|
| 620 |
else:
|
| 621 |
+
st.warning(f"Previously uploaded path no longer exists: {p}")
|
| 622 |
if "uploaded_full_data_path" in st.session_state:
|
| 623 |
del st.session_state.uploaded_full_data_path
|
| 624 |
if not data_path_to_use:
|