fffiloni commited on
Commit
ea6de43
1 Parent(s): b3624b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -18
app.py CHANGED
@@ -54,12 +54,12 @@ def resize_image(input_path, output_path, target_height):
54
 
55
  return output_path
56
 
57
- def infer(image_in, prompt):
58
- prompt = 'Anime style illustration of a girl wearing a suit. A moon in sky. In the background we see a big rain approaching. text "InstantX" on image'
59
  n_prompt = 'NSFW, nude, naked, porn, ugly'
60
 
 
61
  image_to_canny = load_image(image_in)
62
-
63
  image_to_canny = np.array(image_to_canny)
64
  image_to_canny = cv2.Canny(image_to_canny, 100, 200)
65
  image_to_canny = image_to_canny[:, :, None]
@@ -71,38 +71,53 @@ def infer(image_in, prompt):
71
  dict(
72
  control_index=0,
73
  control_image=image_to_canny,
74
- control_weight=0.7,
75
  control_pooled_projections='zeros'
76
  )
77
  ]
 
78
  # infer
79
  image = pipe(
80
  prompt=prompt,
81
  negative_prompt=n_prompt,
82
  controlnet_conditioning=controlnet_conditioning,
83
- num_inference_steps=28,
84
- guidance_scale=7.0,
85
- height=1024,
86
- width=1024,
87
  ).images[0]
88
 
89
- return image
90
-
91
 
92
- with gr.Blocks() as demo:
93
- with gr.Column():
 
 
 
 
 
 
94
  gr.Markdown("""
95
  # SD3 ControlNet
96
  """)
97
- image_in = gr.Image(label="Image reference", sources=["upload"], type="filepath")
98
- prompt = gr.Textbox(label="Prompt")
99
- submit_btn = gr.Button("Submit")
100
- result = gr.Image(label="Result")
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  submit_btn.click(
103
  fn = infer,
104
- inputs = [image_in, prompt],
105
- outputs = [result],
106
  show_api=False
107
  )
108
  demo.queue().launch()
 
54
 
55
  return output_path
56
 
57
+ def infer(image_in, prompt, inference_steps, guidance_scale, control_weight):
58
+
59
  n_prompt = 'NSFW, nude, naked, porn, ugly'
60
 
61
+ # Canny preprocessing
62
  image_to_canny = load_image(image_in)
 
63
  image_to_canny = np.array(image_to_canny)
64
  image_to_canny = cv2.Canny(image_to_canny, 100, 200)
65
  image_to_canny = image_to_canny[:, :, None]
 
71
  dict(
72
  control_index=0,
73
  control_image=image_to_canny,
74
+ control_weight=control_weight,
75
  control_pooled_projections='zeros'
76
  )
77
  ]
78
+
79
  # infer
80
  image = pipe(
81
  prompt=prompt,
82
  negative_prompt=n_prompt,
83
  controlnet_conditioning=controlnet_conditioning,
84
+ num_inference_steps=inference_steps,
85
+ guidance_scale=guidance_scale,
 
 
86
  ).images[0]
87
 
88
+ return image, image_to_canny
 
89
 
90
+ css="""
91
+ #col-container{
92
+ margin: 0 auto;
93
+ max-width: 1080px;
94
+ }
95
+ """
96
+ with gr.Blocks(css=css) as demo:
97
+ with gr.Column(elem_id="col-container"):
98
  gr.Markdown("""
99
  # SD3 ControlNet
100
  """)
101
+ with gr.Row():
102
+ with gr.Column():
103
+ image_in = gr.Image(label="Image reference", sources=["upload"], type="filepath")
104
+ prompt = gr.Textbox(label="Prompt")
105
+ with gr.Accordion("Advanced settings", open=False):
106
+ with gr.Column():
107
+ with gr.Row():
108
+ inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=50, step=1, value=25)
109
+ guidance_scale = gr.Slider(label="Guidance scale", minimum=1.0, maximum=10.0, step=0.1, value=7.0)
110
+ control_weight = gr.Slider(label="Control Weight", minimum=0.0, maximum=1.0, step=0.01, value=0.7)
111
+
112
+ submit_btn = gr.Button("Submit")
113
+ with gr.Column():
114
+ result = gr.Image(label="Result")
115
+ canny_used = gr.Image(label="Preprocessed Canny")
116
 
117
  submit_btn.click(
118
  fn = infer,
119
+ inputs = [image_in, prompt, inference_steps, guidance_scale, control_weight],
120
+ outputs = [result, canny_used],
121
  show_api=False
122
  )
123
  demo.queue().launch()