carraraig's picture
gradio_3 (#4)
acc04ef verified
"""
Main application file for ComputeAgent on HuggingFace Spaces.
Integrates FastAPI backend with Gradio frontend interface.
"""
import os
import sys
import logging
import uvicorn
import gradio as gr
# Add current directory to path
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, current_dir)
# Setup logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger("ComputeAgent-HF")
# Import the FastAPI app from ComputeAgent
from ComputeAgent.main import app as fastapi_app
# Import the Gradio interface
from Gradio_interface import create_gradio_demo
if __name__ == "__main__":
logger.info("=" * 80)
logger.info("πŸ€— ComputeAgent - HuggingFace Spaces Deployment")
logger.info("=" * 80)
# Create Gradio interface
# API will be accessible at the same host since both are mounted together
demo = create_gradio_demo(api_base_url="http://localhost:7860")
# Mount FastAPI into Gradio app
# This combines both apps into a single server on port 7860
app = gr.mount_gradio_app(fastapi_app, demo, path="/")
logger.info("βœ… Combined FastAPI + Gradio app ready")
logger.info("🌐 Server starting on port 7860")
logger.info("=" * 80)
# Uvicorn will serve the combined app on port 7860
uvicorn.run(
app,
host="0.0.0.0",
port=7860,
log_level="info"
)