File size: 1,777 Bytes
b0546d3 ec78ba8 b0546d3 9c06673 b0546d3 e992ee3 b0546d3 e992ee3 b0546d3 e992ee3 b0546d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | # demo/orchestrator.py
from __future__ import annotations
import logging
from typing import Any, Dict, Optional
logger = logging.getLogger(__name__)
# --- Optional Streamlit import (SAFE) ---
try:
import streamlit as st # type: ignore
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,
}
# Optional Streamlit visualization
if self.enable_streamlit and st is not None:
st.json(result)
return result
|