"""UI Integration — PraisonAIUI alongside Gradio and Streamlit. What's New (vs widget/): • Mount PraisonAIUI as a Starlette sub-app inside another framework • Side-by-side with Gradio (ASGI mount) • Streamlit-compatible via iframe embedding pattern • Shows how to add AI chat to any existing web UI Requires: pip install praisonaiui gradio Optional: pip install streamlit (for the Streamlit pattern) Run: python app.py # Landing page at http://localhost:8082 # Or with Gradio: python app.py --gradio """ import os import sys # Use shared seed data helper sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from _shared.console import safe_print as print from _shared.seed_data import seed_demo_data # ── Pattern 1: Gradio + PraisonAIUI (ASGI mount) ──────────────────── def run_with_gradio(): """Mount PraisonAIUI as a sub-app inside Gradio's FastAPI server.""" import gradio as gr from praisonaiui.server import create_app aiui_app = create_app() seed_demo_data() with gr.Blocks(title="AI Agent Dashboard", theme=gr.themes.Soft()) as demo: gr.Markdown("# 🤖 AI Agent Dashboard") gr.Markdown("PraisonAIUI is mounted at `/aiui/` — try the API endpoints below.") with gr.Row(): with gr.Column(scale=2): chatbot = gr.Chatbot(label="Agent Chat", height=400) msg = gr.Textbox(label="Message", placeholder="Ask the agent anything...") send_btn = gr.Button("Send", variant="primary") with gr.Column(scale=1): gr.Markdown("### Quick Links\n- [Features](/aiui/api/features)\n- [Channels](/aiui/api/channels)") status = gr.JSON(label="Server Status", value={"status": "ready"}) refresh_btn = gr.Button("Refresh Status") def chat(message, history): history = history or [] history.append((message, f"Echo: {message}")) return history, "" def get_status(): import httpx try: return httpx.get("http://localhost:7860/aiui/health", timeout=2).json() except Exception: return {"status": "connecting..."} send_btn.click(chat, [msg, chatbot], [chatbot, msg]) msg.submit(chat, [msg, chatbot], [chatbot, msg]) refresh_btn.click(get_status, outputs=status) demo.launch(server_port=7860, prevent_thread_lock=True) gradio_app = demo.server.running_app gradio_app.mount("/aiui", aiui_app) print("\n✅ PraisonAIUI mounted at http://localhost:7860/aiui/") import time try: while True: time.sleep(1) except KeyboardInterrupt: pass # ── Pattern 2: Standalone with HTML embedding page ─────────────────── LANDING_HTML = """
Embed AI agent APIs into Gradio, Streamlit, or any web framework
Mount PraisonAIUI as an ASGI sub-app inside Gradio's FastAPI server.
gradio_app.mount("/aiui", create_app())
Run: python app.py --gradio
Run PraisonAIUI as a sidecar, embed via st.components.iframe().
st.components.v1.iframe("http://localhost:8000/api/features", height=400)
Call PraisonAIUI endpoints from any frontend using fetch/axios.
fetch('/api/channels').then(r => r.json())