NikeZoldyck commited on
Commit
512aa4c
1 Parent(s): 21ddb3c

Fixing instructions

Browse files
Files changed (2) hide show
  1. app.py +25 -22
  2. utils/shared_utils.py +1 -1
app.py CHANGED
@@ -25,13 +25,13 @@ model_id = "CompVis/stable-diffusion-v1-4"
25
  device = "cuda" if torch.cuda.is_available() else "cpu"
26
  context = autocast if device == "cuda" else nullcontext
27
 
28
- pipe = StableDiffusionPipeline.from_pretrained(model_id,use_auth_token=token).to(device)
29
 
30
-
31
- def infer_original(prompt,samples):
32
- with context(device):
33
- images = pipe(samples*[prompt], guidance_scale=7.5).images
34
- return images
35
 
36
 
37
 
@@ -99,15 +99,16 @@ running = """
99
  ### Instructions for running the 3 S's in sequence
100
 
101
  * **Superimpose** - This button allows you to isolate the foreground from your image and overlay it on the background. Remove background using alpha matting
102
- * **Style-Transfer** - Click on "Use this Style" button before this step to lock in the reference style. This button transfer the style from your original image to re-map your new background realistically. Uses Nvidia FastPhotoStyle
103
- * **Smoothing** - Given than image resolutions and clarity can be an issue, this smoothing button makes your final image crisp after the stylization transfer. Fair warning - this last process can take 5-10 mins
104
  """
105
 
106
  style_message = """
107
- This image above will be the content image. By default, the style will be copied from the input foreground image.
108
 
109
- If you have a different image in mind, would you like to upload a different image?
110
- Click yes to add a new style reference image"""
 
111
 
112
 
113
 
@@ -136,7 +137,7 @@ with demo:
136
  with gr.TabItem("Generate via Text Prompt"):
137
  with gr.Box():
138
  with gr.Row().style(mobile_collapse=False, equal_height=True):
139
- text = gr.Textbox(lines=7,
140
  placeholder="Enter your prompt to generate a background image... something like - Photorealistic scenery of bookshelf in a room")
141
 
142
  samples = gr.Slider(label="Number of Images", minimum=1, maximum=5, value=2, step=1)
@@ -144,8 +145,8 @@ with demo:
144
 
145
  gallery = gr.Gallery(label="Generated images", show_label=True).style(grid=(1, 3), height="auto")
146
  # image_options = gr.Radio(label="Pick", interactive=True, choices=None, type="value")
147
- text.submit(infer_original, inputs=[text, samples], outputs=gallery)
148
- btn.click(infer_original, inputs=[text, samples], outputs=gallery, show_progress=True, status_tracker=None)
149
 
150
 
151
  # Second Row - Backgrounds
@@ -169,14 +170,14 @@ with demo:
169
  with gr.Box():
170
  with gr.Column(scale=1):
171
  supimp_btn = gr.Button("SuperImpose")
172
- overlay_img = gr.Image(shape=(800, 800), label="Overlay", type="pil")
173
  gr.Markdown(style_message)
174
  #img_choice = gr.Radio(choices= ["yes"],interactive=True,type='value')
175
- ref_img = gr.Image(shape=(800, 800),label="Style Reference", type="pil",interactive=True)
176
  # ref_img2 = gr.Image(shape=(800, 800), label="Style Reference", type="pil", interactive=True, visible=False)
177
  # ref_btn = gr.Button("Use this style",variant="primary")
178
  #
179
- # ref_btn.click(fn=styleimpose, inputs=[final_input_img, ref_img], outputs=[ref_img2])
180
 
181
  with gr.Column(scale=1):
182
  style_btn = gr.Button("Composition-Transfer",variant="primary")
@@ -186,14 +187,16 @@ with demo:
186
  submit_btn = gr.Button("Smoothen",variant="primary")
187
  output_img = gr.Image(shape=(800, 800),label="FinalSmoothened Image",type="pil")
188
 
189
- supimp_btn.click(fn=st.superimpose, inputs=[final_input_img, final_back_img], outputs=[overlay_img])
190
  style_btn.click(fn=st.style_transfer, inputs=[overlay_img,ref_img], outputs=[style_img])
191
  submit_btn.click(fn=st.smoother, inputs=[style_img,overlay_img], outputs=[output_img])
192
 
193
-
194
- gr.Examples([["profile_new.png","back_img.png"]],[final_input_img, final_back_img])
195
- gr.Examples([["profile_new.png","bedroom with a bookshelf in the background and a small stool to sit on the right side, photorealistic",3]], [final_input_img,text,samples])
196
-
 
 
197
 
198
 
199
  demo.queue(concurrency_count=40, max_size=20).launch(enable_queue=True,max_threads=150)
 
25
  device = "cuda" if torch.cuda.is_available() else "cpu"
26
  context = autocast if device == "cuda" else nullcontext
27
 
28
+ # pipe = StableDiffusionPipeline.from_pretrained(model_id,use_auth_token=token).to(device)
29
 
30
+ #
31
+ # def infer_original(prompt,samples):
32
+ # with context(device):
33
+ # images = pipe(samples*[prompt], guidance_scale=7.5).images
34
+ # return images
35
 
36
 
37
 
 
99
  ### Instructions for running the 3 S's in sequence
100
 
101
  * **Superimpose** - This button allows you to isolate the foreground from your image and overlay it on the background. Remove background using alpha matting
102
+ * **Style-Transfer** - This button transfers the style from your original image to re-map your new background realistically. Uses Nvidia FastPhotoStyle
103
+ * **Smoothing** - Given that the image resolutions and clarity can be an issue, this smoothing button makes your final image, crisp after the stylization transfer. Fair warning - this last process can take 5-10 mins
104
  """
105
 
106
  style_message = """
107
+ This image above will be the content image. By default, a good choice for the style is input foreground image.
108
 
109
+ If you have a different image in mind, you can remove the default and upload it here.
110
+ Ideally transfer works better if your input foreground is also superimposed on the style image, so you may want to create it using the same steps
111
+ ."""
112
 
113
 
114
 
 
137
  with gr.TabItem("Generate via Text Prompt"):
138
  with gr.Box():
139
  with gr.Row().style(mobile_collapse=False, equal_height=True):
140
+ text = gr.Textbox(lines=7, label= "Prompt",
141
  placeholder="Enter your prompt to generate a background image... something like - Photorealistic scenery of bookshelf in a room")
142
 
143
  samples = gr.Slider(label="Number of Images", minimum=1, maximum=5, value=2, step=1)
 
145
 
146
  gallery = gr.Gallery(label="Generated images", show_label=True).style(grid=(1, 3), height="auto")
147
  # image_options = gr.Radio(label="Pick", interactive=True, choices=None, type="value")
148
+ text.submit(infer, inputs=[text, samples], outputs=gallery)
149
+ btn.click(infer, inputs=[text, samples], outputs=gallery, show_progress=True, status_tracker=None)
150
 
151
 
152
  # Second Row - Backgrounds
 
170
  with gr.Box():
171
  with gr.Column(scale=1):
172
  supimp_btn = gr.Button("SuperImpose")
173
+ overlay_img = gr.Image(shape=(800, 800), label="Overlay/Content Image", type="pil")
174
  gr.Markdown(style_message)
175
  #img_choice = gr.Radio(choices= ["yes"],interactive=True,type='value')
176
+ ref_img = gr.Image(shape=(800, 800),label="Style Reference Image", type="pil",interactive=True)
177
  # ref_img2 = gr.Image(shape=(800, 800), label="Style Reference", type="pil", interactive=True, visible=False)
178
  # ref_btn = gr.Button("Use this style",variant="primary")
179
  #
180
+ # ref_btn.click(fn=styleimpose, inputs=[final_input_img, ref_img], outputs=[ref_img])
181
 
182
  with gr.Column(scale=1):
183
  style_btn = gr.Button("Composition-Transfer",variant="primary")
 
187
  submit_btn = gr.Button("Smoothen",variant="primary")
188
  output_img = gr.Image(shape=(800, 800),label="FinalSmoothened Image",type="pil")
189
 
190
+ supimp_btn.click(fn=st.superimpose, inputs=[final_input_img, final_back_img], outputs=[overlay_img,ref_img])
191
  style_btn.click(fn=st.style_transfer, inputs=[overlay_img,ref_img], outputs=[style_img])
192
  submit_btn.click(fn=st.smoother, inputs=[style_img,overlay_img], outputs=[output_img])
193
 
194
+ gr.Examples(examples=[["profile_new.png","back_img.png"]], label="AlphaMatting- Remove BG",
195
+ inputs=[final_input_img, final_back_img], outputs=[overlay_img])
196
+ gr.Examples(examples=[["profile_new.png",
197
+ "bedroom with a bookshelf in the background and a small stool to sit on the right side, photorealistic",
198
+ 3]],inputs= [final_input_img,text,samples], label="Text2Img - Stable Diffisuon")
199
+ gr.Examples(examples=[["cont_img.png","ref_img.png"]],inputs=[overlay_img, ref_img], label = "Nvidia - FastPhotoStyle")
200
 
201
 
202
  demo.queue(concurrency_count=40, max_size=20).launch(enable_queue=True,max_threads=150)
utils/shared_utils.py CHANGED
@@ -81,7 +81,7 @@ def memory_limit_image_resize(cont_img):
81
  def superimpose(input_img,back_img):
82
  matte_img = remove(input_img)
83
  back_img.paste(matte_img, (0, 0), matte_img)
84
- return back_img
85
 
86
 
87
 
 
81
  def superimpose(input_img,back_img):
82
  matte_img = remove(input_img)
83
  back_img.paste(matte_img, (0, 0), matte_img)
84
+ return back_img,input_img
85
 
86
 
87