Spaces:
Paused
Paused
File size: 2,039 Bytes
7ed2180 | 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 | # 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() |