Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +29 -22
streamlit_app.py
CHANGED
|
@@ -346,6 +346,9 @@ def main() -> None:
|
|
| 346 |
if not st.session_state.get("video_path"):
|
| 347 |
st.info("Load a video first.", icon="ℹ️")
|
| 348 |
|
|
|
|
|
|
|
|
|
|
| 349 |
if generate_now and not st.session_state.get("busy", False):
|
| 350 |
api_key = st.session_state.get("api_key") or os.getenv("GOOGLE_API_KEY")
|
| 351 |
if not st.session_state.get("video_path"):
|
|
@@ -357,14 +360,14 @@ def main() -> None:
|
|
| 357 |
st.session_state["busy"] = True
|
| 358 |
genai.configure(api_key=api_key)
|
| 359 |
|
| 360 |
-
#
|
| 361 |
with st.spinner("Checking video size…"):
|
| 362 |
video_path, was_compressed = _maybe_compress(
|
| 363 |
Path(st.session_state["video_path"]),
|
| 364 |
st.session_state["compress_mb"],
|
| 365 |
)
|
| 366 |
|
| 367 |
-
#
|
| 368 |
with st.spinner("Generating analysis…"):
|
| 369 |
raw_out = generate_report(
|
| 370 |
video_path,
|
|
@@ -374,7 +377,7 @@ def main() -> None:
|
|
| 374 |
)
|
| 375 |
st.session_state["raw_output"] = raw_out
|
| 376 |
|
| 377 |
-
#
|
| 378 |
if was_compressed:
|
| 379 |
try:
|
| 380 |
video_path.unlink()
|
|
@@ -383,6 +386,7 @@ def main() -> None:
|
|
| 383 |
|
| 384 |
cleaned = _strip_prompt_echo(st.session_state["prompt"], raw_out)
|
| 385 |
st.session_state["analysis_out"] = cleaned
|
|
|
|
| 386 |
st.success("Analysis generated.")
|
| 387 |
st.markdown(cleaned or "*(no output)*")
|
| 388 |
|
|
@@ -397,25 +401,28 @@ def main() -> None:
|
|
| 397 |
finally:
|
| 398 |
st.session_state["busy"] = False
|
| 399 |
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
st.code(st.session_state["last_error_detail"], language="text")
|
| 418 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
if __name__ == "__main__":
|
| 421 |
-
main()
|
|
|
|
| 346 |
if not st.session_state.get("video_path"):
|
| 347 |
st.info("Load a video first.", icon="ℹ️")
|
| 348 |
|
| 349 |
+
# ------------------------------------------------------------------
|
| 350 |
+
# Generation button handling (unchanged up to the end of the try/except)
|
| 351 |
+
# ------------------------------------------------------------------
|
| 352 |
if generate_now and not st.session_state.get("busy", False):
|
| 353 |
api_key = st.session_state.get("api_key") or os.getenv("GOOGLE_API_KEY")
|
| 354 |
if not st.session_state.get("video_path"):
|
|
|
|
| 360 |
st.session_state["busy"] = True
|
| 361 |
genai.configure(api_key=api_key)
|
| 362 |
|
| 363 |
+
# ----- optional compression -----
|
| 364 |
with st.spinner("Checking video size…"):
|
| 365 |
video_path, was_compressed = _maybe_compress(
|
| 366 |
Path(st.session_state["video_path"]),
|
| 367 |
st.session_state["compress_mb"],
|
| 368 |
)
|
| 369 |
|
| 370 |
+
# ----- generation -----
|
| 371 |
with st.spinner("Generating analysis…"):
|
| 372 |
raw_out = generate_report(
|
| 373 |
video_path,
|
|
|
|
| 377 |
)
|
| 378 |
st.session_state["raw_output"] = raw_out
|
| 379 |
|
| 380 |
+
# ----- clean up compressed file -----
|
| 381 |
if was_compressed:
|
| 382 |
try:
|
| 383 |
video_path.unlink()
|
|
|
|
| 386 |
|
| 387 |
cleaned = _strip_prompt_echo(st.session_state["prompt"], raw_out)
|
| 388 |
st.session_state["analysis_out"] = cleaned
|
| 389 |
+
st.session_state["show_analysis"] = True # ← new flag
|
| 390 |
st.success("Analysis generated.")
|
| 391 |
st.markdown(cleaned or "*(no output)*")
|
| 392 |
|
|
|
|
| 401 |
finally:
|
| 402 |
st.session_state["busy"] = False
|
| 403 |
|
| 404 |
+
# ------------------------------------------------------------------
|
| 405 |
+
# Results – displayed **once** after a successful generation
|
| 406 |
+
# ------------------------------------------------------------------
|
| 407 |
+
if st.session_state.get("show_analysis"):
|
| 408 |
+
st.subheader("📝 Analysis")
|
| 409 |
+
st.markdown(st.session_state["analysis_out"])
|
| 410 |
+
# Reset the flag so the block won’t run on the next automatic rerun
|
| 411 |
+
st.session_state["show_analysis"] = False
|
| 412 |
+
|
| 413 |
+
# Full Gemini output – collapsed by default, expanded on error
|
| 414 |
+
if st.session_state.get("raw_output"):
|
| 415 |
+
if st.session_state.get("show_raw_on_error"):
|
| 416 |
+
st.subheader("🔎 Full Gemini output")
|
| 417 |
+
st.code(st.session_state["raw_output"], language="text")
|
| 418 |
+
else:
|
| 419 |
+
with st.expander("🔎 Full Gemini output (collapsed)"):
|
| 420 |
+
st.code(st.session_state["raw_output"], language="text")
|
|
|
|
| 421 |
|
| 422 |
+
# Errors
|
| 423 |
+
if st.session_state.get("last_error"):
|
| 424 |
+
with st.expander("❗️ Error details"):
|
| 425 |
+
st.code(st.session_state["last_error_detail"], language="text")
|
| 426 |
|
| 427 |
if __name__ == "__main__":
|
| 428 |
+
main()
|