Spaces:
Paused
Paused
| # filename: app.py | |
| # PAM - Privacy-First AI Assistant | |
| # Main entry point for local development and testing | |
| import os | |
| import sys | |
| import uvicorn | |
| from api_service import app | |
| # Configuration | |
| HOST = os.getenv("PAM_HOST", "0.0.0.0") | |
| PORT = int(os.getenv("PAM_PORT", "7860")) | |
| RELOAD = os.getenv("PAM_RELOAD", "false").lower() == "true" | |
| LOG_LEVEL = os.getenv("PAM_LOG_LEVEL", "info") | |
| def main(): | |
| """ | |
| Start the PAM service with Uvicorn | |
| Environment Variables: | |
| PAM_HOST: Host to bind to (default: 0.0.0.0) | |
| PAM_PORT: Port to bind to (default: 7860) | |
| PAM_RELOAD: Enable auto-reload for development (default: false) | |
| PAM_LOG_LEVEL: Logging level (default: info) | |
| """ | |
| print("=" * 60) | |
| print("π€ PAM - Privacy-First AI Assistant") | |
| print("=" * 60) | |
| print(f"π Frontend PAM: Sweet Southern Receptionist") | |
| print(f"π€ Backend PAM: Nerdy Lab Assistant") | |
| print("=" * 60) | |
| print(f"π Server: http://{HOST}:{PORT}") | |
| print(f"π API Docs: http://{HOST}:{PORT}/docs") | |
| print(f"π₯ Health Check: http://{HOST}:{PORT}/health") | |
| print("=" * 60) | |
| # Check for HF token | |
| hf_token = os.getenv("HF_READ_TOKEN") | |
| if not hf_token: | |
| print("β οΈ WARNING: HF_READ_TOKEN not set!") | |
| print(" Set it in your environment or Hugging Face Space settings") | |
| print("=" * 60) | |
| else: | |
| print("β HF_READ_TOKEN detected") | |
| print("=" * 60) | |
| try: | |
| uvicorn.run( | |
| app, | |
| host=HOST, | |
| port=PORT, | |
| reload=RELOAD, | |
| log_level=LOG_LEVEL, | |
| access_log=True, | |
| workers=1, # Single worker for HF Spaces | |
| timeout_keep_alive=75 | |
| ) | |
| except KeyboardInterrupt: | |
| print("\nπ PAM shutting down gracefully...") | |
| sys.exit(0) | |
| except Exception as e: | |
| print(f"\nβ Error starting PAM: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() |