File size: 795 Bytes
b1d9da9 6664141 |
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 |
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import gradio as gr
# Your existing Gradio interface code here
def image_generator(prompt):
# Your image generation logic here
pass
interface = gr.Interface(fn=image_generator, inputs="text", outputs="image")
# Wrap the Gradio interface with FastAPI
app = FastAPI()
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Add your domain(s) here
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Mount the Gradio app
app = gr.mount_gradio_app(app, interface, path="/")
# If you're not using Gradio, you can just use FastAPI directly:
# @app.post("/predict")
# async def predict(data: dict):
# # Your prediction logic here
# pass |