disable negative prompt when None
Browse files
app.py
CHANGED
|
@@ -12,22 +12,25 @@ inference = DiffusionInference()
|
|
| 12 |
controlnet = ControlNetPipeline()
|
| 13 |
|
| 14 |
def text_to_image_fn(prompt, model, negative_prompt=None, guidance_scale=7.5, num_inference_steps=50):
|
| 15 |
-
"""
|
| 16 |
-
Handle text to image generation request
|
| 17 |
-
"""
|
| 18 |
try:
|
| 19 |
# Model validation - fallback to default if empty
|
| 20 |
if not model or model.strip() == '':
|
| 21 |
model = config.DEFAULT_TEXT2IMG_MODEL
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
prompt
|
| 26 |
-
model_name
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if image is None:
|
| 33 |
return None, "No image was generated. Check the model and parameters."
|
|
|
|
| 12 |
controlnet = ControlNetPipeline()
|
| 13 |
|
| 14 |
def text_to_image_fn(prompt, model, negative_prompt=None, guidance_scale=7.5, num_inference_steps=50):
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
# Model validation - fallback to default if empty
|
| 17 |
if not model or model.strip() == '':
|
| 18 |
model = config.DEFAULT_TEXT2IMG_MODEL
|
| 19 |
|
| 20 |
+
# Create kwargs dictionary for parameters
|
| 21 |
+
kwargs = {
|
| 22 |
+
"prompt": prompt,
|
| 23 |
+
"model_name": model,
|
| 24 |
+
"guidance_scale": guidance_scale,
|
| 25 |
+
"num_inference_steps": num_inference_steps
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Only add negative_prompt if it's not None
|
| 29 |
+
if negative_prompt is not None:
|
| 30 |
+
kwargs["negative_prompt"] = negative_prompt
|
| 31 |
+
|
| 32 |
+
# Call the inference module with unpacked kwargs
|
| 33 |
+
image = inference.text_to_image(**kwargs)
|
| 34 |
|
| 35 |
if image is None:
|
| 36 |
return None, "No image was generated. Check the model and parameters."
|