SyntheticVis-Umut commited on
Commit ·
90cb6f6
1
Parent(s): e3a8a3d
Switch to SDXL Turbo model and fix parameters
Browse files
app.py
CHANGED
|
@@ -8,8 +8,8 @@ from huggingface_hub import InferenceClient
|
|
| 8 |
app = FastAPI(title="ImageGen API")
|
| 9 |
|
| 10 |
# Choose a model that supports text->image via Inference API.
|
| 11 |
-
#
|
| 12 |
-
MODEL_ID = os.getenv("MODEL_ID", "
|
| 13 |
HF_TOKEN = os.getenv("HF_TOKEN") # set in Space Secrets
|
| 14 |
client = InferenceClient(model=MODEL_ID, token=HF_TOKEN)
|
| 15 |
|
|
@@ -30,9 +30,10 @@ def generate(req: GenReq):
|
|
| 30 |
# InferenceClient returns a PIL.Image for text_to_image
|
| 31 |
img = client.text_to_image(
|
| 32 |
prompt=req.prompt,
|
| 33 |
-
|
|
|
|
| 34 |
seed=req.seed,
|
| 35 |
-
num_inference_steps=req.num_inference_steps
|
| 36 |
)
|
| 37 |
buf = io.BytesIO()
|
| 38 |
img.save(buf, format="PNG")
|
|
|
|
| 8 |
app = FastAPI(title="ImageGen API")
|
| 9 |
|
| 10 |
# Choose a model that supports text->image via Inference API.
|
| 11 |
+
# SDXL Turbo is fast; you can swap for other models later.
|
| 12 |
+
MODEL_ID = os.getenv("MODEL_ID", "stabilityai/sdxl-turbo")
|
| 13 |
HF_TOKEN = os.getenv("HF_TOKEN") # set in Space Secrets
|
| 14 |
client = InferenceClient(model=MODEL_ID, token=HF_TOKEN)
|
| 15 |
|
|
|
|
| 30 |
# InferenceClient returns a PIL.Image for text_to_image
|
| 31 |
img = client.text_to_image(
|
| 32 |
prompt=req.prompt,
|
| 33 |
+
width=req.width,
|
| 34 |
+
height=req.height,
|
| 35 |
seed=req.seed,
|
| 36 |
+
num_inference_steps=req.num_inference_steps or 1 # SDXL Turbo works best with 1 step
|
| 37 |
)
|
| 38 |
buf = io.BytesIO()
|
| 39 |
img.save(buf, format="PNG")
|