petter2025's picture
Update demo/orchestrator.py
b0546d3 verified
raw
history blame
1.78 kB
# 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