Commit
·
b3b1893
1
Parent(s):
72d441c
fix: mount FastAPI router into Gradio app for API endpoints on port 7860
Browse files
app.py
CHANGED
|
@@ -250,23 +250,18 @@ with gr.Blocks(title="Video Face Swap", theme=gr.themes.Soft()) as demo:
|
|
| 250 |
demo.queue()
|
| 251 |
|
| 252 |
if __name__ == "__main__":
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
# Only start API if not in Gradio's main thread
|
| 266 |
-
if os.environ.get("GRADIO_SERVER_NAME") is None:
|
| 267 |
-
api_thread = threading.Thread(target=run_api, daemon=True)
|
| 268 |
-
api_thread.start()
|
| 269 |
-
print("FastAPI server starting on port 8000...")
|
| 270 |
|
| 271 |
-
# Launch Gradio app
|
| 272 |
demo.launch(server_port=7860, share=False)
|
|
|
|
| 250 |
demo.queue()
|
| 251 |
|
| 252 |
if __name__ == "__main__":
|
| 253 |
+
# Mount FastAPI routes into Gradio's FastAPI app
|
| 254 |
+
try:
|
| 255 |
+
from api.main import app as api_app
|
| 256 |
+
|
| 257 |
+
# Mount API routes directly to Gradio's FastAPI app
|
| 258 |
+
# demo.app is the FastAPI instance used by Gradio
|
| 259 |
+
demo.app.include_router(api_app.router)
|
| 260 |
+
print("✅ FastAPI routes mounted to Gradio app")
|
| 261 |
+
except Exception as e:
|
| 262 |
+
print(f"API integration error: {e}")
|
| 263 |
+
import traceback
|
| 264 |
+
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
+
# Launch Gradio app (FastAPI routes are now accessible on same port 7860)
|
| 267 |
demo.launch(server_port=7860, share=False)
|