Hug0endob commited on
Commit
122d093
·
verified ·
1 Parent(s): b66b025

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +45 -45
streamlit_app.py CHANGED
@@ -339,58 +339,58 @@ def main() -> None:
339
  )
340
 
341
  # ---------- Main panel ----------
342
- # Run Analysis button
343
- if st.button("Run Analysis"):
344
- if not st.session_state.get("video_path"):
345
- st.error("No video loaded – load a video first.")
346
- elif not st.session_state.get("api_key"):
347
- st.error("Google API key missing – enter it in the sidebar.")
348
- else:
349
  # Configure Gemini model with safety settings
350
- safety_settings = [
351
- {
352
- "category": "HARM_CATEGORY_HARASSMENT",
353
- "threshold": "BLOCK_NONE"
354
- },
355
- {
356
- "category": "HARM_CATEGORY_HATE_SPEECH",
357
- "threshold": "BLOCK_NONE"
358
- },
359
- {
360
- "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
361
- "threshold": "BLOCK_NONE"
362
- },
363
- {
364
- "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
365
- "threshold": "BLOCK_NONE"
366
- }
367
- ]
368
 
369
  # Configure Gemini with API key and safety settings
370
  genai.configure(api_key=st.session_state["api_key"],
371
  safety_settings=safety_settings) # Set safety to lowest (none)
372
 
373
- st.session_state["busy"] = True
374
- st.session_state["analysis_out"] = ""
375
- st.session_state["raw_output"] = ""
376
- st.session_state["last_error"] = ""
377
- st.session_state["last_error_detail"] = ""
378
 
379
- try:
380
- with st.spinner("Generating report (this may take a minute)…"):
381
- raw = generate_report(
382
- Path(st.session_state["video_path"]),
383
- st.session_state["prompt"],
384
- st.session_state["model_input"],
385
- )
386
- cleaned = _strip_prompt_echo(st.session_state["prompt"], raw)
387
- st.session_state["analysis_out"] = cleaned
388
- st.session_state["raw_output"] = raw
389
- except Exception as e:
390
- st.session_state["last_error"] = f"Analysis failed: {e}"
391
- st.session_state["last_error_detail"] = traceback.format_exc()
392
- finally:
393
- st.session_state["busy"] = False
394
 
395
  # ---- Layout: analysis first, then video, then errors ----
396
  if st.session_state.get("analysis_out"):
 
339
  )
340
 
341
  # ---------- Main panel ----------
342
+ # Run Analysis button
343
+ if st.button("Run Analysis"):
344
+ if not st.session_state.get("video_path"):
345
+ st.error("No video loaded – load a video first.")
346
+ elif not st.session_state.get("api_key"):
347
+ st.error("Google API key missing – enter it in the sidebar.")
348
+ else:
349
  # Configure Gemini model with safety settings
350
+ safety_settings = [
351
+ {
352
+ "category": "HARM_CATEGORY_HARASSMENT",
353
+ "threshold": "BLOCK_NONE"
354
+ },
355
+ {
356
+ "category": "HARM_CATEGORY_HATE_SPEECH",
357
+ "threshold": "BLOCK_NONE"
358
+ },
359
+ {
360
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
361
+ "threshold": "BLOCK_NONE"
362
+ },
363
+ {
364
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
365
+ "threshold": "BLOCK_NONE"
366
+ }
367
+ ]
368
 
369
  # Configure Gemini with API key and safety settings
370
  genai.configure(api_key=st.session_state["api_key"],
371
  safety_settings=safety_settings) # Set safety to lowest (none)
372
 
373
+ st.session_state["busy"] = True
374
+ st.session_state["analysis_out"] = ""
375
+ st.session_state["raw_output"] = ""
376
+ st.session_state["last_error"] = ""
377
+ st.session_state["last_error_detail"] = ""
378
 
379
+ try:
380
+ with st.spinner("Generating report (this may take a minute)…"):
381
+ raw = generate_report(
382
+ Path(st.session_state["video_path"]),
383
+ st.session_state["prompt"],
384
+ st.session_state["model_input"],
385
+ )
386
+ cleaned = _strip_prompt_echo(st.session_state["prompt"], raw)
387
+ st.session_state["analysis_out"] = cleaned
388
+ st.session_state["raw_output"] = raw
389
+ except Exception as e:
390
+ st.session_state["last_error"] = f"Analysis failed: {e}"
391
+ st.session_state["last_error_detail"] = traceback.format_exc()
392
+ finally:
393
+ st.session_state["busy"] = False
394
 
395
  # ---- Layout: analysis first, then video, then errors ----
396
  if st.session_state.get("analysis_out"):