devjas1 commited on
Commit
a003091
·
1 Parent(s): a781694

(FEAT/REFAC)[UI/UX]: Implement comprehensive UI rendering and state management

Browse files

This commit finalizes the structure of `ui_components.py`, which serves as the central module for rendering all user interface elements of the Polymer Analysis application using Streamlit. It defines the layout, handles user input, and displays analysis results in a structured and interactive manner.

#### File Structure and Key Functions:

The module is organized into several high-level functions, each responsible for a distinct part of the UI:

1. **`render_sidebar()`**:
* **Purpose**: Constructs the application's main sidebar.
* **Functionality**: Includes the app title, modality selection (Raman/FTIR), and a dynamic AI model selector. It fetches and displays metadata for the chosen model (accuracy, F1-score) and provides an expandable "About" section with project details, contributor credits, and relevant links.

2. **`render_input_column()`**:
* **Purpose**: Manages all data input mechanisms.
* **Functionality**: Provides a radio-button interface to switch between three input modes: "Upload File" (for single spectrum analysis), "Batch Upload" (for multiple files), and "Sample Data" (for using pre-loaded examples). It handles file uploads, updates session state with the input data, and displays status messages to the user. It also contains the primary "Run Analysis" button, which is enabled based on the application's readiness state.

3. **`render_results_column()`**:
* **Purpose**: Displays the output of the analysis.
* **Functionality**: Its behavior is conditional on the input mode:
* **Single File Mode**: Renders a detailed, multi-tabbed view ("Details", "Technical", "Explanation") showing the prediction, confidence scores, performance metrics, raw model outputs (logits), and scientific context. It also includes a visualization of the raw vs. preprocessed spectrum.
* **Batch Mode**: Defers to the `ResultsManager` to display a comprehensive, sortable table of results for all processed files.

4. **`render_comparison_tab()`**:
* **Purpose**: Provides a dedicated workspace for comparing the performance of multiple AI models on a single data sample.
* **Functionality**: Users can select multiple models, upload a spectrum file, and run a comparison. The results are displayed in a summary table and visualized through charts comparing model confidence and processing time.
* **Refactoring**: This component has been intentionally simplified to **exclusively use synchronous (sequential) processing**. The `st.checkbox` for enabling asynchronous execution and all related logic have been removed. This change standardizes the execution flow, making it more predictable, stable, and easier to debug, at the cost of concurrent processing speed for large model sets.

5. **`render_performance_tab()`**:
* **Purpose**: Acts as the entry point for the performance dashboard.
* **Functionality**: Calls the `display_performance_dashboard` utility to render historical performance metrics and analysis.

#### Helper UI Functions:

The module also contains several reusable helper functions for creating consistent UI elements:
* `create_spectrum_plot()`: Generates a cached Matplotlib plot of the spectrum.
* `render_confidence_progress()`: Renders styled progress bars for class probabilities.
* `render_kv_grid()`: Displays dictionaries as a clean key-value grid.
* `get_confidence_description()`: Maps numerical confidence scores to human-readable levels.

Overall, this file establishes a clear and maintainable structure for the application's front end, with a logical separation of concerns between different UI sections.

Files changed (1) hide show
  1. modules/ui_components.py +0 -0
modules/ui_components.py CHANGED
The diff for this file is too large to render. See raw diff