File size: 1,457 Bytes
0417005
 
 
 
 
 
 
 
 
 
 
acc04ef
 
 
 
0417005
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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"
    )