PAM-UmiNur / app.py
pythonprincess's picture
Upload 14 files
7ed2180 verified
# 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()