Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Instant SWOT Agent - Unified Entry Point | |
| Provides CLI access to all application modes: | |
| - api: Start FastAPI backend server | |
| - streamlit: Start Streamlit dashboard | |
| - analyze: Run CLI analysis for a stock | |
| Usage: | |
| python -m src.main api [--host HOST] [--port PORT] | |
| python -m src.main streamlit | |
| python -m src.main analyze TICKER [--strategy STRATEGY] | |
| """ | |
| import sys | |
| import click | |
| def cli(): | |
| """Instant SWOT Agent - Multi-agent SWOT analysis with self-correction.""" | |
| pass | |
| def api(host: str, port: int, reload: bool): | |
| """Start the FastAPI backend server.""" | |
| import uvicorn | |
| click.echo(f"Starting Instant SWOT Agent API on {host}:{port}") | |
| uvicorn.run( | |
| "src.api.app:app", | |
| host=host, | |
| port=port, | |
| reload=reload | |
| ) | |
| def streamlit(port: int): | |
| """Start the Streamlit dashboard.""" | |
| import subprocess | |
| click.echo(f"Starting Instant SWOT Agent Streamlit UI on port {port}") | |
| subprocess.run([ | |
| sys.executable, '-m', 'streamlit', 'run', | |
| 'streamlit_app.py', | |
| '--server.port', str(port) | |
| ]) | |
| def analyze(ticker: str, company: str, strategy: str, output: str): | |
| """Run SWOT analysis for a stock ticker. | |
| Example: | |
| python -m src.main analyze AAPL | |
| python -m src.main analyze TSLA --company "Tesla Inc" --strategy "Cost Leadership" | |
| """ | |
| import json | |
| from src.workflow.runner import run_self_correcting_workflow | |
| company_name = company or ticker | |
| click.echo(f"Analyzing {company_name} ({ticker})...") | |
| click.echo(f"Strategy focus: {strategy}") | |
| click.echo("-" * 50) | |
| try: | |
| result = run_self_correcting_workflow( | |
| company_name=company_name, | |
| ticker=ticker, | |
| strategy_focus=strategy | |
| ) | |
| if output == 'json': | |
| output_data = { | |
| "company_name": company_name, | |
| "ticker": ticker, | |
| "strategy_focus": strategy, | |
| "score": result.get("score", 0), | |
| "revision_count": result.get("revision_count", 0), | |
| "provider_used": result.get("provider_used"), | |
| "data_source": result.get("data_source"), | |
| "draft_report": result.get("draft_report", ""), | |
| "critique": result.get("critique", "") | |
| } | |
| click.echo(json.dumps(output_data, indent=2)) | |
| else: | |
| # Text output | |
| click.echo(f"\nScore: {result.get('score', 0)}/10") | |
| click.echo(f"Revisions: {result.get('revision_count', 0)}") | |
| click.echo(f"Provider: {result.get('provider_used', 'unknown')}") | |
| click.echo("\n" + "=" * 50) | |
| click.echo("SWOT ANALYSIS") | |
| click.echo("=" * 50) | |
| click.echo(result.get("draft_report", "No report generated")) | |
| if result.get("critique"): | |
| click.echo("\n" + "-" * 50) | |
| click.echo("CRITIQUE") | |
| click.echo("-" * 50) | |
| click.echo(result.get("critique")) | |
| except Exception as e: | |
| click.echo(f"Error: {str(e)}", err=True) | |
| sys.exit(1) | |
| def info(): | |
| """Show system information and configuration status.""" | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| click.echo("Instant SWOT Agent - System Info") | |
| click.echo("=" * 40) | |
| # LLM Providers | |
| click.echo("\nLLM Providers:") | |
| providers = [ | |
| ("GROQ_API_KEY", "Groq"), | |
| ("GEMINI_API_KEY", "Gemini"), | |
| ("OPENROUTER_API_KEY", "OpenRouter") | |
| ] | |
| for env_var, name in providers: | |
| status = "configured" if os.getenv(env_var) else "not configured" | |
| click.echo(f" {name}: {status}") | |
| # Data Sources | |
| click.echo("\nData Sources:") | |
| sources = [ | |
| ("FRED_API_KEY", "FRED (Macro data)"), | |
| ("FINNHUB_API_KEY", "Finnhub (Sentiment)") | |
| ] | |
| for env_var, name in sources: | |
| status = "configured" if os.getenv(env_var) else "not configured" | |
| click.echo(f" {name}: {status}") | |
| click.echo("\nEntry Points:") | |
| click.echo(" API: python -m src.main api") | |
| click.echo(" Streamlit: python -m src.main streamlit") | |
| click.echo(" CLI: python -m src.main analyze <TICKER>") | |
| if __name__ == "__main__": | |
| cli() | |