Ashoka74 commited on
Commit
f8ff0a0
·
verified ·
1 Parent(s): 6180e6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -33
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import spaces
2
  import argparse
3
  import random
@@ -85,6 +88,28 @@ def infer(
85
  return images, preprocessed_image, seed
86
 
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  with gr.Blocks() as demo:
89
  with gr.Row():
90
  gr.Markdown(
@@ -153,9 +178,44 @@ Generate 768x768 multi-view images from a single image using SDXL <br>
153
  placeholder="Enter your negative prompt",
154
  value="watermark, ugly, deformed, noisy, blurry, low contrast",
155
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  imgs = gr.State()
158
-
159
  with gr.Column():
160
  result = gr.Gallery(
161
  label="Result",
@@ -166,50 +226,61 @@ Generate 768x768 multi-view images from a single image using SDXL <br>
166
  height="auto",
167
  allow_preview=False,
168
  )
169
-
170
- # Slider to select image index
171
- slider = gr.Slider(
172
- minimum=0,
173
- maximum=5,
174
- step=1,
175
- label="Select Image Index",
176
- value=0, # Default value
177
- interactive=True
178
- )
179
 
180
- input_fg = gr.Image(type="numpy", label="Selected Image", height=480)
181
 
182
- def update_selected_image(selected_index:int, images):
183
- """Selects the appropriate image"""
184
- try:
185
- selected_index=int(selected_index)
186
- if 0 <= selected_index < len(images):
187
- return images[selected_index]
188
- except (ValueError, TypeError):
189
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
- slider.change(
192
  fn=update_selected_image,
193
  inputs=[slider, imgs],
194
  outputs=input_fg
195
- )
 
196
 
 
 
 
 
 
 
 
 
197
 
198
- gr.on(
199
- triggers=[run_button.click, prompt.submit],
200
  fn=infer,
201
  inputs=[
202
  prompt,
203
- input_image,
204
- do_rembg,
205
- seed,
206
- randomize_seed,
207
- guidance_scale,
208
- num_inference_steps,
209
- reference_conditioning_scale,
210
- negative_prompt,
211
  ],
212
- outputs=[result, preprocessed_image, seed, imgs],
213
  )
214
 
215
  demo.launch()
 
1
+ ew Image-to-Image Generation
2
+ drivecheck
3
+ Optional tone and style instructions for the model
4
  import spaces
5
  import argparse
6
  import random
 
88
  return images, preprocessed_image, seed
89
 
90
 
91
+ # examples = [
92
+ # [
93
+ # "A decorative figurine of a young anime-style girl",
94
+ # "assets/demo/i2mv/A_decorative_figurine_of_a_young_anime-style_girl.png",
95
+ # True,
96
+ # 21,
97
+ # ],
98
+ # [
99
+ # "A juvenile emperor penguin chick",
100
+ # "assets/demo/i2mv/A_juvenile_emperor_penguin_chick.png",
101
+ # True,
102
+ # 0,
103
+ # ],
104
+ # [
105
+ # "A striped tabby cat with white fur sitting upright",
106
+ # "assets/demo/i2mv/A_striped_tabby_cat_with_white_fur_sitting_upright.png",
107
+ # True,
108
+ # 0,
109
+ # ],
110
+ # ]
111
+
112
+
113
  with gr.Blocks() as demo:
114
  with gr.Row():
115
  gr.Markdown(
 
178
  placeholder="Enter your negative prompt",
179
  value="watermark, ugly, deformed, noisy, blurry, low contrast",
180
  )
181
+
182
+ def use_orientation(selected_image:gr.SelectData):
183
+ return selected_image.index
184
+
185
+ def add_orientation(imgs, index):
186
+ index = int(index)
187
+ return imgs[index]
188
+
189
+ # def get_image_by_index(imgs, index):
190
+ # """
191
+ # Retrieves the image from the imgs list based on the provided index.
192
+ # """
193
+ # try:
194
+ # index = int(index)
195
+ # if 0 <= index < len(imgs):
196
+ # return imgs[index]
197
+ # else:
198
+ # return None # Or return a placeholder image
199
+ # except (ValueError, TypeError):
200
+ # return None # Or return a placeholder image
201
+
202
+
203
+ def set_slider_index(selected_image):
204
+ return selected_image.index
205
+
206
+ def update_selected_image(selected_index:int, images):
207
+ """Selects the appropriate image"""
208
+ try:
209
+ selected_index=int(selected_index)
210
+ if 0 <= selected_index < len(images):
211
+ return images[selected_index]
212
+ except (ValueError, TypeError):
213
+ return None
214
+
215
+
216
 
217
  imgs = gr.State()
218
+
219
  with gr.Column():
220
  result = gr.Gallery(
221
  label="Result",
 
226
  height="auto",
227
  allow_preview=False,
228
  )
 
 
 
 
 
 
 
 
 
 
229
 
230
+
231
 
232
+ if len(result) > 0:
233
+ # Slider to select image index
234
+ slider = gr.Slider(
235
+ minimum=0,
236
+ maximum=5,
237
+ step=1,
238
+ label="Select Image Index",
239
+ value=0, # Default value
240
+ interactive=True
241
+ )
242
+
243
+ input_fg = gr.Image(type="numpy", label="Selected Image", height=480)
244
+ # selected = gr.Number(visible=True)
245
+ # result.select(use_orientation, None, selected).then()
246
+ # add_button = gr.Button("Select orientation for processing")
247
+ # add_button.click(add_orientation, [imgs, selected], input_fg)
248
+
249
+ #result.select(
250
+ # fn=set_slider_index,
251
+ # inputs=result,
252
+ # outputs=slider
253
+ #)
254
+
255
+ #slider.change(
256
+ # fn=use_orientation,
257
+ # inputs=[result, slider],
258
+ # outputs=input_fg
259
+ #)
260
 
261
+ slider.change(
262
  fn=update_selected_image,
263
  inputs=[slider, imgs],
264
  outputs=input_fg
265
+ )
266
+
267
 
268
+ # with gr.Row():
269
+ # gr.Examples(
270
+ # examples=examples,
271
+ # fn=infer,
272
+ # inputs=[prompt, input_image, do_rembg, seed],
273
+ # outputs=[result, preprocessed_image, seed],
274
+ # cache_examples=True,
275
+ # )
276
 
277
+ run_button.click(
 
278
  fn=infer,
279
  inputs=[
280
  prompt,
281
+ input_fg,
 
 
 
 
 
 
 
282
  ],
283
+ outputs=[result],
284
  )
285
 
286
  demo.launch()