Spaces:
Running
Running
๐ Refactored Code Structure
The application has been refactored into modular components for better maintainability and understanding.
๐๏ธ File Structure
๐ฆ Bahngleiserfassung/
โโโ ๐ฏ app.py # Main Streamlit application (refactored)
โโโ ๐น video_processing.py # Video frame extraction and repair utilities
โโโ ๐ง ontology_integration.py # Ontology-based scene analysis and risk assessment
โโโ ๐ค model_processing.py # Local and remote AI model processing
โโโ ๐ฅ๏ธ ui_components.py # Streamlit UI components and rendering
โโโ ๐งฎ ontology_eval.py # Core ontology evaluation logic (unchanged)
โโโ ๐ฌ local_models.py # Local AI models (ViT, BLIP) (unchanged)
โโโ ๐พ app_original_backup.py # Backup of original monolithic app.py
๐ Module Responsibilities
๐ฏ app.py - Main Application
- Purpose: Main entry point and orchestration
- Functions:
- Application initialization and layout
- Model setup and configuration
- Main processing workflow coordination
- Input validation and error handling
๐น video_processing.py - Video Processing
- Purpose: Video frame extraction and repair
- Functions:
extract_frames_from_video()- Extract frames at specified FPSrepair_video_with_ffmpeg()- Repair corrupted video files- Handle various video formats (MP4, AVI, MOV, MKV)
๐ง ontology_integration.py - Ontology Analysis
- Purpose: Scene analysis using ontology-based risk assessment
- Functions:
analyze_scene_with_ontology()- Main ontology analysis function_extract_ontology_features()- Extract features from scene descriptions_calculate_person_on_track_confidence()- Calculate specific risk confidenceextract_scene_description()- Extract text from model results
๐ค model_processing.py - Model Processing
- Purpose: Handle local and remote AI model processing
- Functions:
process_image_locally()- Process images using local modelsquery_huggingface_api()- Process images using remote HF APIprocess_frame()- Unified frame processing interfaceimage_to_base64()- Image conversion utilities
๐ฅ๏ธ ui_components.py - UI Components
- Purpose: Streamlit UI components and rendering
- Functions:
render_sidebar_config()- Configuration sidebarrender_input_section()- Video upload interfacerender_frame_result()- Display frame analysis resultsrender_validation_errors()- Show validation messages- Various helper rendering functions
๐ Data Flow
graph TD
A[app.py] --> B[ui_components.py]
A --> C[video_processing.py]
A --> D[model_processing.py]
A --> E[ontology_integration.py]
C --> F[Extract Frames]
D --> G[Process with AI Models]
E --> H[Ontology Risk Assessment]
F --> G
G --> H
H --> B
I[local_models.py] --> D
J[ontology_eval.py] --> E
โจ Benefits of Refactoring
- ๐งฉ Modularity: Each module has a single responsibility
- ๐ง Maintainability: Easier to update and debug individual components
- ๐ Readability: Clear separation of concerns and smaller, focused files
- ๐งช Testability: Each module can be tested independently
- ๐ Reusability: Components can be reused in other projects
- ๐ฅ Collaboration: Multiple developers can work on different modules
๐ Usage
The refactored application works exactly the same as before:
streamlit run app.py
All functionality remains identical:
- โ NONE / ๐ข LOW / ๐ MEDIUM / โ ๏ธ HIGH / ๐จ CRITICAL classification
- Toggle ontology analysis on/off
- Support for local and remote AI models
- Video processing with automatic repair
๐ Backwards Compatibility
- Original functionality is preserved
- API and interface remain unchanged
- Configuration and settings work the same way
- The original monolithic code is backed up as
app_original_backup.py