stablediffusion / main.py
aka7774's picture
Upload 6 files
530a0a9 verified
raw
history blame
1.03 kB
import os
import sys
import time
import signal
import psutil
import io
from fastapi import FastAPI, Request, status, Form, UploadFile
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel, Field
from fastapi.exceptions import RequestValidationError
from fastapi.responses import Response
import fn
import gradio as gr
from app import demo
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
gr.mount_gradio_app(app, demo, path="/gradio")
@app.post("/run")
async def api_run(prompt = None, negative_prompt = None, model = None, guidance_scale = None, steps = None, seed = None):
try:
dst_image = fn.run(prompt, negative_prompt, model, guidance_scale, steps, seed)
bin = fn.pil_to_webp(dst_image)
return Response(content=bin, media_type="image/webp")
except Exception as e:
return {"error": str(e)}