File size: 2,678 Bytes
a8da4e0 2bf5660 a8da4e0 2bf5660 a8da4e0 2bf5660 a8da4e0 0f25023 a8da4e0 2bf5660 a8da4e0 |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#!/usr/bin/env python3
"""
Main entry point for FaceForge application
"""
import os
import logging
import sys
import traceback
# Configure logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[logging.StreamHandler(sys.stdout)]
)
logger = logging.getLogger("faceforge")
def main():
"""Main function to start the FaceForge application."""
try:
# Apply the patch for Gradio
logger.info("Applying Gradio patch...")
try:
from patch_gradio_utils import apply_patch
if apply_patch():
logger.info("Gradio patch applied successfully.")
else:
logger.warning("Failed to apply Gradio patch. The app may encounter errors.")
except Exception as e:
logger.warning(f"Error applying Gradio patch: {e}")
logger.debug(traceback.format_exc())
# Set up FastAPI application with both API and UI
logger.info("Setting up FastAPI application with API and UI")
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import gradio as gr
# Import the API and UI components
from faceforge_api.main import app as api_app
from faceforge_ui.app import create_demo
# Create a new FastAPI application that will serve as the main app
app = FastAPI(title="FaceForge")
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Mount the API under /api
logger.info("Mounting API at /api")
app.mount("/api", api_app)
# Create Gradio UI
logger.info("Creating Gradio UI")
demo = create_demo()
# Mount Gradio UI
logger.info("Mounting Gradio UI")
gr_app = gr.mount_gradio_app(app, demo, path="/")
# Configure server
import uvicorn
port = int(os.environ.get("PORT", 7860))
logger.info(f"Starting integrated server on port {port}")
uvicorn.run(app, host="0.0.0.0", port=port)
except ImportError as e:
logger.critical(f"Import error: {e}. Please check your dependencies.")
logger.debug(traceback.format_exc())
sys.exit(1)
except Exception as e:
logger.critical(f"Unexpected error: {e}")
logger.debug(traceback.format_exc())
sys.exit(1)
if __name__ == "__main__":
main() |