Spaces:
Sleeping
Sleeping
File size: 7,397 Bytes
226b286 |
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
#!/usr/bin/env python3
"""
Universal App Launcher for AgenticAI Projects
Usage:
python run.py <app_name> [--port PORT] [--help]
Examples:
python run.py healthcare
python run.py deep-research --port 8502
python run.py stock-analyst
python run.py --list
"""
import sys
import os
import subprocess
import argparse
from pathlib import Path
from typing import Dict, Optional
from agents import Runner, SQLiteSession
# from agents import set_trace_processors
# from langsmith.wrappers import OpenAIAgentsTracingProcessor
# Load environment variables explicitly
from dotenv import load_dotenv
load_dotenv(override=True)
# App registry - maps app names to their paths and entry points
APP_REGISTRY: Dict[str, Dict[str, str]] = {
"healthcare": {
"path": "src/healthcare-assistant",
"entry": "app.py",
"description": "Healthcare Assistant - Medical information with RAG and web search"
},
"deep-research": {
"path": "src/deep-research",
"entry": "app.py",
"description": "Deep Research AI - Comprehensive research assistant"
},
"stock-analyst": {
"path": "src/stock-analyst",
"entry": "app.py",
"description": "Stock Analyst - Financial analysis and stock recommendations"
},
"travel-agent": {
"path": "src/travel-agent",
"entry": "app.py",
"description": "Travel Agent - Trip planning and travel recommendations"
},
"trip-planner": {
"path": "src/trip-planner",
"entry": "main.py",
"description": "Trip Planner - Detailed trip itinerary planning"
},
"chatbot": {
"path": "src/chatbot",
"entry": "app.py",
"description": "General Chatbot - Multi-purpose conversational AI"
},
"accessibility": {
"path": "src/accessibility",
"entry": "app.py",
"description": "Accessibility Tools - Assistive technology applications"
},
"literature-review": {
"path": "src/literature-review",
"entry": "app.py",
"description": "Literature Review Assistant - Multi-agent literature review tool"
},
"market-analyst": {
"path": "src/market-analyst",
"entry": "app.py",
"description": "Market Analyst - Multi-agent market analysis tool"
},
"image": {
"path": "src/image-generator",
"entry": "app.py",
"description": "Image Generator - Multi-agent image generation tool"
},
"interview-assistant": {
"path": "src/interview-assistant",
"entry": "app.py",
"description": "Interview Assistant - Multi-agent interview tool"
}
}
def print_banner():
"""Print a nice banner."""
print("=" * 70)
print("π AgenticAI Projects Launcher".center(70))
print("=" * 70)
print()
def list_apps():
"""List all available apps."""
print_banner()
print("Available Applications:\n")
max_name_len = max(len(name) for name in APP_REGISTRY.keys())
for name, config in sorted(APP_REGISTRY.items()):
print(f" {name.ljust(max_name_len + 2)} - {config['description']}")
print("\n" + "=" * 70)
print("\nUsage: python run.py <app_name> [--port PORT]")
print("Example: python run.py healthcare --port 8501\n")
def validate_app(app_name: str) -> Optional[Dict[str, str]]:
"""
Validate that the app exists and its files are present.
Args:
app_name: Name of the app to validate
Returns:
App configuration dict if valid, None otherwise
"""
if app_name not in APP_REGISTRY:
print(f"β Error: Unknown app '{app_name}'")
print(f"\nAvailable apps: {', '.join(sorted(APP_REGISTRY.keys()))}")
print("\nRun 'python run.py --list' to see all available apps.")
return None
config = APP_REGISTRY[app_name]
project_root = Path(__file__).parent
app_path = project_root / config["path"] / config["entry"]
if not app_path.exists():
print(f"β Error: App file not found at {app_path}")
return None
return config
def launch_app(app_name: str, port: Optional[int] = None):
"""
Launch a Streamlit app.
Args:
app_name: Name of the app to launch
port: Optional port number (default: 8501)
"""
config = validate_app(app_name)
if not config:
sys.exit(1)
project_root = Path(__file__).parent
app_dir = project_root / config["path"]
app_file = config["entry"]
print_banner()
print(f"π± Launching: {config['description']}")
print(f"π Location: {config['path']}")
print(f"π Entry Point: {app_file}")
# Build streamlit command
cmd = ["streamlit", "run", app_file]
# Add port if specified
if port:
cmd.extend(["--server.port", str(port)])
print(f"π Port: {port}")
else:
print(f"π Port: 8501 (default)")
print("\n" + "=" * 70)
print("\nπ― Starting application...\n")
# Prepare environment with project root in PYTHONPATH to fix imports
env = os.environ.copy()
env["PYTHONPATH"] = str(project_root) + os.pathsep + env.get("PYTHONPATH", "")
print(f"\n\nPYTHONPATH: {env['PYTHONPATH']}")
try:
# Change to app directory and run
os.chdir(app_dir)
subprocess.run(cmd, env=env)
except KeyboardInterrupt:
print("\n\nπ Application stopped by user")
except FileNotFoundError:
print("\nβ Error: Streamlit not found. Please install it:")
print(" pip install streamlit")
sys.exit(1)
except Exception as e:
print(f"\nβ Error launching app: {e}")
sys.exit(1)
def main():
"""Main entry point."""
parser = argparse.ArgumentParser(
description="Universal launcher for AgenticAI project applications",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python run.py healthcare # Launch healthcare chatbot
python run.py deep-research --port 8502 # Launch on custom port
python run.py --list # List all available apps
Available Apps:
""" + "\n ".join(f"{name}: {config['description']}"
for name, config in sorted(APP_REGISTRY.items()))
)
parser.add_argument(
"app_name",
nargs="?",
help="Name of the app to launch"
)
parser.add_argument(
"--port",
type=int,
help="Port number for Streamlit server (default: 8501)"
)
parser.add_argument(
"--list",
action="store_true",
help="List all available apps"
)
args = parser.parse_args()
# Handle --list flag
if args.list:
list_apps()
return
# Require app name if not listing
if not args.app_name:
parser.print_help()
print("\n")
list_apps()
return
# Launch the app
launch_app(args.app_name, args.port)
if __name__ == "__main__":
# set_trace_processors([OpenAIAgentsTracingProcessor()])
main()
|