Spaces:
Sleeping
Sleeping
File size: 927 Bytes
93e4e76 220c6b7 39715d4 220c6b7 cb758ea 02c6aa4 6be6a10 2dba8b2 00e5d15 02c6aa4 2dba8b2 3f6b0bd 220c6b7 cb758ea e7326f0 cb758ea 4e49f93 cb758ea 220c6b7 |
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 pydantic import BaseModel
import requests # Добавляем импорт
import asyncio
from contextlib import asynccontextmanager
from diffusers import DiffusionPipeline
@asynccontextmanager
async def lifespan(app: FastAPI):
# Здесь можно инициализировать ресурсы
yield
# Здесь можно освободить ресурсы
app = FastAPI(lifespan=lifespan)
class ImageRequest(BaseModel): # Новая модель для запроса
prompt: str = "girl in red dress"
@app.post("/generate-image")
async def generate_image(request: ImageRequest):
try:
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell")
prompt = request.prompt
image = pipe(prompt).images[0]
return image
except Exception as e:
return {"error": str(e)} |