Spaces:
Sleeping
Sleeping
File size: 1,339 Bytes
c840ad0 |
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 |
"""Main application entry point for PromptAR Backend API."""
import logging
from utils.logging_config import setup_colored_logging
from app.app import create_app, set_hf_service
from config import HOST, PORT, HF_TOKEN
# Setup colored logging before creating app
setup_colored_logging()
logger = logging.getLogger(__name__)
# Create FastAPI application
app = create_app()
async def startup_event():
"""Handle application startup events."""
# Initialize HuggingFaceService (works with or without HF_TOKEN)
try:
from services.huggingface_service import HuggingFaceService
logger.info("Initializing HuggingFaceService")
hf_service = HuggingFaceService()
set_hf_service(hf_service)
logger.info("✓ HuggingFaceService initialized successfully")
except Exception as e:
logger.error(f"❌ Failed to initialize HuggingFaceService: {e}")
set_hf_service(None)
if not HF_TOKEN:
logger.warning(
"⚠️ HF_TOKEN not configured - Some Spaces may require authentication"
)
logger.info(
"API server started. Visit http://localhost:8000/docs for API documentation"
)
# Register startup event
app.on_event("startup")(startup_event)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host=HOST, port=PORT)
|