Spaces:
Sleeping
Sleeping
File size: 1,158 Bytes
83379ae | 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 | 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)
|