Skip to content

Commit f666907

Browse files
committed
Improved image gen server apis.
1 parent 0d5742e commit f666907

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

nexa/gguf/server/nexa_service.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
NEXA_RUN_MODEL_MAP_AUDIO_LM,
3434
NEXA_RUN_AUDIO_LM_PROJECTOR_MAP,
3535
NEXA_RUN_COMPLETION_TEMPLATE_MAP,
36-
NEXA_RUN_MODEL_PRECISION_MAP,
3736
NEXA_RUN_MODEL_MAP_FUNCTION_CALLING,
3837
NEXA_MODEL_LIST_PATH,
3938
NEXA_OFFICIAL_BUCKET,
@@ -181,14 +180,14 @@ class Config:
181180
extra = "allow"
182181

183182

184-
class TextToImageRequest(BaseModel):
185-
prompt: str = "a lovely cat holding a sign says 'Nexa Server'"
186-
negative_prompt: Optional[str] = ""
187-
cfg_scale: Optional[float] = 7.0
188-
width: Optional[int] = 512
189-
height: Optional[int] = 512
190-
sample_steps: Optional[int] = 20
191-
seed: Optional[int] = 42
183+
# class TextToImageRequest(BaseModel):
184+
# prompt: str = "a lovely cat holding a sign says 'Nexa Server'"
185+
# negative_prompt: Optional[str] = ""
186+
# cfg_scale: Optional[float] = 7.0
187+
# width: Optional[int] = 512
188+
# height: Optional[int] = 512
189+
# sample_steps: Optional[int] = 20
190+
# seed: Optional[int] = 42
192191

193192

194193
class TextToSpeechRequest(BaseModel):
@@ -1526,15 +1525,24 @@ async def function_call(request: FunctionCallRequest):
15261525

15271526

15281527
@app.post("/v1/txt2img", tags=["Computer Vision"])
1529-
async def txt2img(request: TextToImageRequest):
1528+
async def txt2img(
1529+
prompt: str = Form("a lovely cat holding a sign says 'Nexa Server'"),
1530+
negative_prompt: Optional[str] = Form(""),
1531+
cfg_scale: Optional[float] = Form(7.0, description="set to 1.0 when using Flux for optimal results"),
1532+
width: Optional[int] = Form(512),
1533+
height: Optional[int] = Form(512),
1534+
sample_steps: Optional[int] = Form(20, description="set to 4 when using Flux for optimal results"),
1535+
seed: Optional[int] = Form(42),
1536+
):
15301537
try:
15311538
if model_type != "Computer Vision":
15321539
raise HTTPException(
15331540
status_code=400,
15341541
detail="The model that is loaded is not a Computer Vision model. Please use a Computer Vision model for image generation."
15351542
)
1536-
generation_kwargs = request.dict()
1537-
generated_images = await nexa_run_text_to_image(**generation_kwargs)
1543+
generated_images = await nexa_run_text_to_image(prompt=prompt, negative_prompt=negative_prompt,
1544+
cfg_scale=cfg_scale, width=width, height=height,
1545+
sample_steps=sample_steps,seed=seed)
15381546

15391547
resp = {"created": time.time(), "data": []}
15401548

@@ -1557,16 +1565,15 @@ async def txt2img(request: TextToImageRequest):
15571565

15581566

15591567
@app.post("/v1/img2img", tags=["Computer Vision"])
1560-
# async def img2img(request: ImageToImageRequest):
15611568
async def img2img(
1562-
prompt: str = Form("a lovely cat holding a sign says 'Nexa Server'"),
1569+
prompt: str = Form("Convert the image to grayscale."),
15631570
image: UploadFile = File(...),
15641571
negative_prompt: Optional[str] = Form(""),
15651572
strength: Optional[float] = Form(0.75),
1566-
cfg_scale: Optional[float] = Form(7.0),
1573+
cfg_scale: Optional[float] = Form(7.0, description="set to 1.0 when using Flux for optimal results"),
15671574
width: Optional[int] = Form(512),
15681575
height: Optional[int] = Form(512),
1569-
sample_steps: Optional[int] = Form(20),
1576+
sample_steps: Optional[int] = Form(20, description="set to 4 when using Flux for optimal results"),
15701577
seed: Optional[int] = Form(42),
15711578
):
15721579
try:

0 commit comments

Comments
 (0)