Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -207,7 +207,12 @@ def check_password() -> bool:
|
|
| 207 |
|
| 208 |
|
| 209 |
def main():
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
with st.expander("Diagnostics (Versionen)"):
|
| 212 |
versions = {}
|
| 213 |
try:
|
|
@@ -225,85 +230,59 @@ def main():
|
|
| 225 |
try:
|
| 226 |
import PIL; versions["pillow"] = PIL.__version__
|
| 227 |
except Exception: versions["pillow"] = "n/a"
|
| 228 |
-
|
| 229 |
st.write(versions)
|
| 230 |
|
| 231 |
-
|
| 232 |
-
# Initialize application
|
| 233 |
-
initialize_app()
|
| 234 |
if not check_password():
|
| 235 |
st.stop()
|
| 236 |
-
|
|
|
|
| 237 |
settings = load_settings()
|
| 238 |
local_manager, local_models_available = setup_local_models()
|
| 239 |
-
|
| 240 |
-
#
|
| 241 |
col1, col2 = st.columns([1, 1])
|
| 242 |
-
|
| 243 |
with col1:
|
| 244 |
-
# Render sidebar configuration
|
| 245 |
config = render_sidebar_config(settings, local_models_available, local_manager)
|
| 246 |
-
|
| 247 |
-
# Render input section
|
| 248 |
input_data = render_input_section()
|
| 249 |
video_file = input_data["video_file"]
|
| 250 |
-
|
| 251 |
-
# Render prompt section
|
| 252 |
prompt = render_prompt_section(config)
|
| 253 |
-
|
| 254 |
-
# Render process button
|
| 255 |
process_button = render_process_button()
|
| 256 |
-
|
| 257 |
with col2:
|
| 258 |
-
# Render results section
|
| 259 |
results_container = render_results_header()
|
| 260 |
-
|
| 261 |
-
#
|
| 262 |
if process_button:
|
| 263 |
if validate_inputs(video_file, prompt, config, local_models_available):
|
| 264 |
-
# Add prompt to config for processing
|
| 265 |
config["prompt"] = prompt
|
| 266 |
-
|
| 267 |
with st.spinner("Processing video..."):
|
| 268 |
-
# Process video frames
|
| 269 |
results = process_video_frames(video_file, config, local_manager)
|
| 270 |
-
|
| 271 |
-
# Display results
|
| 272 |
if results:
|
| 273 |
with results_container:
|
| 274 |
st.subheader("Analysis Results")
|
| 275 |
-
|
| 276 |
-
# Display summary statistics
|
| 277 |
severity_counts = {}
|
| 278 |
-
for
|
| 279 |
-
|
| 280 |
-
severity_counts[
|
| 281 |
-
|
| 282 |
if config["use_ontology"] and severity_counts:
|
| 283 |
st.write("**Summary:**")
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
'
|
| 289 |
-
}
|
| 290 |
-
with summary_cols[i]:
|
| 291 |
-
st.metric(f"{icon_map.get(severity, '❓')} {severity}", count)
|
| 292 |
st.divider()
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
for result_data in results:
|
| 296 |
-
render_frame_result(result_data)
|
| 297 |
else:
|
| 298 |
-
# Show validation errors
|
| 299 |
render_validation_errors(
|
| 300 |
-
video_file, prompt, config["api_token"],
|
| 301 |
config["model_type"], local_models_available, config["selected_model"]
|
| 302 |
)
|
| 303 |
-
|
| 304 |
-
# Render instructions
|
| 305 |
render_instructions()
|
| 306 |
|
| 307 |
|
|
|
|
| 308 |
if __name__ == "__main__":
|
| 309 |
main()
|
|
|
|
| 207 |
|
| 208 |
|
| 209 |
def main():
|
| 210 |
+
"""Main application entry point"""
|
| 211 |
+
|
| 212 |
+
# 1) Seite konfigurieren (muss der erste Streamlit-Call sein)
|
| 213 |
+
initialize_app()
|
| 214 |
+
|
| 215 |
+
# 2) Diagnostics anzeigen (Versionen)
|
| 216 |
with st.expander("Diagnostics (Versionen)"):
|
| 217 |
versions = {}
|
| 218 |
try:
|
|
|
|
| 230 |
try:
|
| 231 |
import PIL; versions["pillow"] = PIL.__version__
|
| 232 |
except Exception: versions["pillow"] = "n/a"
|
|
|
|
| 233 |
st.write(versions)
|
| 234 |
|
| 235 |
+
# 3) Passwort prüfen
|
|
|
|
|
|
|
| 236 |
if not check_password():
|
| 237 |
st.stop()
|
| 238 |
+
|
| 239 |
+
# 4) Settings & Modelle
|
| 240 |
settings = load_settings()
|
| 241 |
local_manager, local_models_available = setup_local_models()
|
| 242 |
+
|
| 243 |
+
# 5) Layout & UI
|
| 244 |
col1, col2 = st.columns([1, 1])
|
|
|
|
| 245 |
with col1:
|
|
|
|
| 246 |
config = render_sidebar_config(settings, local_models_available, local_manager)
|
|
|
|
|
|
|
| 247 |
input_data = render_input_section()
|
| 248 |
video_file = input_data["video_file"]
|
|
|
|
|
|
|
| 249 |
prompt = render_prompt_section(config)
|
|
|
|
|
|
|
| 250 |
process_button = render_process_button()
|
|
|
|
| 251 |
with col2:
|
|
|
|
| 252 |
results_container = render_results_header()
|
| 253 |
+
|
| 254 |
+
# 6) Logik
|
| 255 |
if process_button:
|
| 256 |
if validate_inputs(video_file, prompt, config, local_models_available):
|
|
|
|
| 257 |
config["prompt"] = prompt
|
|
|
|
| 258 |
with st.spinner("Processing video..."):
|
|
|
|
| 259 |
results = process_video_frames(video_file, config, local_manager)
|
|
|
|
|
|
|
| 260 |
if results:
|
| 261 |
with results_container:
|
| 262 |
st.subheader("Analysis Results")
|
|
|
|
|
|
|
| 263 |
severity_counts = {}
|
| 264 |
+
for r in results:
|
| 265 |
+
sev = r['ontology_analysis'].get('severity', 'NONE')
|
| 266 |
+
severity_counts[sev] = severity_counts.get(sev, 0) + 1
|
|
|
|
| 267 |
if config["use_ontology"] and severity_counts:
|
| 268 |
st.write("**Summary:**")
|
| 269 |
+
cols = st.columns(len(severity_counts))
|
| 270 |
+
icon = {'NONE':'✅','LOW':'🟢','MEDIUM':'🟠','HIGH':'⚠️','CRITICAL':'🚨'}
|
| 271 |
+
for i,(sev,cnt) in enumerate(severity_counts.items()):
|
| 272 |
+
with cols[i]:
|
| 273 |
+
st.metric(f"{icon.get(sev,'❓')} {sev}", cnt)
|
|
|
|
|
|
|
|
|
|
| 274 |
st.divider()
|
| 275 |
+
for rd in results:
|
| 276 |
+
render_frame_result(rd)
|
|
|
|
|
|
|
| 277 |
else:
|
|
|
|
| 278 |
render_validation_errors(
|
| 279 |
+
video_file, prompt, config["api_token"],
|
| 280 |
config["model_type"], local_models_available, config["selected_model"]
|
| 281 |
)
|
| 282 |
+
|
|
|
|
| 283 |
render_instructions()
|
| 284 |
|
| 285 |
|
| 286 |
+
|
| 287 |
if __name__ == "__main__":
|
| 288 |
main()
|