Spaces:
Runtime error
Runtime error
Fix: Create FastAPI app first, mount Gradio onto it
Browse filesCustom routes now take precedence over Gradio's catch-all.
Use gr.mount_gradio_app() to properly integrate both apps.
app.py
CHANGED
|
@@ -11,7 +11,7 @@ import re
|
|
| 11 |
import sys
|
| 12 |
import warnings
|
| 13 |
|
| 14 |
-
from fastapi import Request
|
| 15 |
from fastapi.responses import StreamingResponse
|
| 16 |
|
| 17 |
from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler
|
|
@@ -500,7 +500,11 @@ init_app()
|
|
| 500 |
pipe.transformer.layers._repeated_blocks = ["ZImageTransformerBlock"]
|
| 501 |
spaces.aoti_blocks_load(pipe.transformer.layers, "zerogpu-aoti/Z-Image", variant="fa3")
|
| 502 |
|
| 503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 504 |
gr.Markdown(
|
| 505 |
"""<div align="center">
|
| 506 |
|
|
@@ -586,11 +590,11 @@ with gr.Blocks(title="Z-Image Generation MCP") as demo:
|
|
| 586 |
api_name="generate_image", # nice, stable name for tool clients
|
| 587 |
)
|
| 588 |
|
| 589 |
-
#
|
| 590 |
-
|
|
|
|
| 591 |
|
| 592 |
|
| 593 |
-
# ==================== /generate/<prompt>.png Endpoint ====================
|
| 594 |
@app.get("/generate/{prompt_path:path}")
|
| 595 |
def http_generate_png(
|
| 596 |
prompt_path: str,
|
|
@@ -691,10 +695,9 @@ def http_generate_png(
|
|
| 691 |
return StreamingResponse(io.BytesIO(png_bytes), media_type="image/png")
|
| 692 |
|
| 693 |
|
| 694 |
-
#
|
|
|
|
| 695 |
|
| 696 |
-
css = """
|
| 697 |
-
.fillable{max-width: 1230px !important}
|
| 698 |
-
"""
|
| 699 |
if __name__ == "__main__":
|
| 700 |
-
|
|
|
|
|
|
| 11 |
import sys
|
| 12 |
import warnings
|
| 13 |
|
| 14 |
+
from fastapi import FastAPI, Request
|
| 15 |
from fastapi.responses import StreamingResponse
|
| 16 |
|
| 17 |
from diffusers import AutoencoderKL, FlowMatchEulerDiscreteScheduler
|
|
|
|
| 500 |
pipe.transformer.layers._repeated_blocks = ["ZImageTransformerBlock"]
|
| 501 |
spaces.aoti_blocks_load(pipe.transformer.layers, "zerogpu-aoti/Z-Image", variant="fa3")
|
| 502 |
|
| 503 |
+
css = """
|
| 504 |
+
.fillable{max-width: 1230px !important}
|
| 505 |
+
"""
|
| 506 |
+
|
| 507 |
+
with gr.Blocks(title="Z-Image Generation MCP", css=css) as demo:
|
| 508 |
gr.Markdown(
|
| 509 |
"""<div align="center">
|
| 510 |
|
|
|
|
| 590 |
api_name="generate_image", # nice, stable name for tool clients
|
| 591 |
)
|
| 592 |
|
| 593 |
+
# ==================== FastAPI App with Custom Routes ====================
|
| 594 |
+
# Create our own FastAPI app so custom routes take precedence over Gradio's catch-all
|
| 595 |
+
app = FastAPI()
|
| 596 |
|
| 597 |
|
|
|
|
| 598 |
@app.get("/generate/{prompt_path:path}")
|
| 599 |
def http_generate_png(
|
| 600 |
prompt_path: str,
|
|
|
|
| 695 |
return StreamingResponse(io.BytesIO(png_bytes), media_type="image/png")
|
| 696 |
|
| 697 |
|
| 698 |
+
# Mount Gradio app onto our FastAPI app
|
| 699 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
| 700 |
|
|
|
|
|
|
|
|
|
|
| 701 |
if __name__ == "__main__":
|
| 702 |
+
import uvicorn
|
| 703 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|