| |
| from __future__ import annotations |
|
|
| import logging |
| from typing import Any, Dict, Optional |
|
|
| logger = logging.getLogger(__name__) |
|
|
| |
| try: |
| import streamlit as st |
| except Exception: |
| st = None |
| logger.info("Streamlit not available; running in non-Streamlit mode.") |
|
|
|
|
| class DemoOrchestrator: |
| """ |
| Orchestrates demo scenarios. |
| |
| Streamlit is OPTIONAL and never required at import time. |
| This prevents Hugging Face Spaces from crashing. |
| """ |
|
|
| def __init__(self, enable_streamlit: bool = False): |
| self.enable_streamlit = enable_streamlit and st is not None |
|
|
| if enable_streamlit and st is None: |
| logger.warning( |
| "Streamlit requested but not installed. " |
| "Proceeding without Streamlit UI." |
| ) |
|
|
| def render_streamlit(self) -> None: |
| """ |
| Render Streamlit UI if available. |
| Safe no-op otherwise. |
| """ |
| if not self.enable_streamlit or st is None: |
| logger.debug("Streamlit UI disabled or unavailable.") |
| return |
|
|
| st.title("Agentic Reliability Framework Demo") |
| st.markdown("Interactive demo running inside Streamlit.") |
|
|
| def run_scenario(self, scenario: Dict[str, Any]) -> Dict[str, Any]: |
| """ |
| Run a demo scenario without any UI dependency. |
| """ |
| logger.info("Running scenario: %s", scenario.get("name", "unknown")) |
|
|
| result = { |
| "scenario": scenario.get("name"), |
| "status": "completed", |
| "output": scenario, |
| } |
|
|
| |
| if self.enable_streamlit and st is not None: |
| st.json(result) |
|
|
| return result |
|
|