import gradio as gr from fastapi import FastAPI import sys import os # Ensure the current directory is in the path so imports work correctly sys.path.append(os.path.dirname(os.path.abspath(__file__))) # 1. Import the PureVersation Gradio UI # The original UI is defined in main.py as 'demo' try: from main import demo as pureversation_ui except ImportError as e: print(f"Warning: Could not import main.py demo: {e}") # Fallback placeholder with gr.Blocks() as pureversation_ui: gr.Markdown("# PureVersation UI Loading...") # 2. Import the PureKITchat FastAPI app try: from api import app as purekitchat_api except ImportError as e: print(f"Warning: Could not import api.py: {e}") purekitchat_api = FastAPI() # 3. Mount the Gradio UI onto the FastAPI app # This makes FastAPI the master server. It handles /api routes natively, # and passes all other traffic (like /) to the Gradio UI. app = gr.mount_gradio_app(purekitchat_api, pureversation_ui, path="/") if __name__ == "__main__": import uvicorn # HuggingFace Spaces defaults to port 7860 uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=False)