abi445's picture
Update pythonproject.py
b1d9da9 verified
raw
history blame contribute delete
795 Bytes
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