forked from aredden/flux-fp8-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
33 lines (26 loc) · 907 Bytes
/
api.py
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
32
33
from typing import Optional
import numpy as np
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
from pydantic import BaseModel, Field
from platform import system
if system() == "Windows":
MAX_RAND = 2**16 - 1
else:
MAX_RAND = 2**32 - 1
app = FastAPI()
class GenerateArgs(BaseModel):
prompt: str
width: Optional[int] = Field(default=720)
height: Optional[int] = Field(default=1024)
num_steps: Optional[int] = Field(default=24)
guidance: Optional[float] = Field(default=3.5)
seed: Optional[int] = Field(
default_factory=lambda: np.random.randint(0, MAX_RAND), gt=0, lt=MAX_RAND
)
strength: Optional[float] = 1.0
init_image: Optional[str] = None
@app.post("/generate")
def generate(args: GenerateArgs):
result = app.state.model.generate(**args.model_dump())
return StreamingResponse(result, media_type="image/jpeg")