ar0551 commited on
Commit
4cc1869
·
verified ·
1 Parent(s): 9f93059

added handling of no image provided

Browse files
Files changed (1) hide show
  1. app.py +29 -15
app.py CHANGED
@@ -86,21 +86,35 @@ def apply_canny(image, low_threshold, high_threshold):
86
  def generate_image(prompt, input_image, low_threshold, high_threshold, strength, guidance, controlnet_conditioning_scale):
87
 
88
  print(pipe.get_active_adapters())
89
-
90
- # Apply edge detection
91
- edge_detected = apply_canny(input_image, low_threshold, high_threshold)
92
-
93
- # Generate styled image using ControlNet
94
- result = pipe(
95
- prompt=prompt,
96
- image=edge_detected,
97
- num_inference_steps=30,
98
- guidance_scale=guidance,
99
- controlnet_conditioning_scale=float(controlnet_conditioning_scale),
100
- strength=strength
101
- ).images[0]
102
-
103
- return edge_detected, result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  # 🖥️ Gradio UI
106
  with gr.Blocks() as demo:
 
86
  def generate_image(prompt, input_image, low_threshold, high_threshold, strength, guidance, controlnet_conditioning_scale):
87
 
88
  print(pipe.get_active_adapters())
89
+ print(input_image)
90
+
91
+ ## execute if an image is provided
92
+ if input_image is not None:
93
+ # Apply edge detection
94
+ edge_detected = apply_canny(input_image, low_threshold, high_threshold)
95
+
96
+ # Generate styled image using ControlNet
97
+ result = pipe(
98
+ prompt=prompt,
99
+ image=edge_detected,
100
+ num_inference_steps=30,
101
+ guidance_scale=guidance,
102
+ controlnet_conditioning_scale=float(controlnet_conditioning_scale),
103
+ strength=strength
104
+ ).images[0]
105
+
106
+ return edge_detected, result
107
+
108
+ else:
109
+ # Generate styled image using ControlNet
110
+ result = pipe(
111
+ prompt=prompt,
112
+ num_inference_steps=30,
113
+ guidance_scale=guidance,
114
+ strength=strength
115
+ ).images[0]
116
+
117
+ return None, result
118
 
119
  # 🖥️ Gradio UI
120
  with gr.Blocks() as demo: