tokeron commited on
Commit
c3eb335
·
verified ·
1 Parent(s): 896cd0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -26
app.py CHANGED
@@ -1,48 +1,70 @@
1
  import gradio as gr
2
  from diffusion_lens import get_images
3
 
4
-
5
-
6
-
7
-
8
- def generate_images(prompt, all_images):
9
  print('calling diffusion lens')
10
- # all_images = [] # Initialize a list to store all images
11
  for skip_layers in range(11, -1, -1):
12
  images = get_images(prompt, skip_layers=skip_layers)
13
- all_images.append(images[0]) # (images[0], f'layer_{12 - skip_layers}')) # Add the new image to the list
14
- yield all_images # Yield the list of all images
15
 
16
  with gr.Blocks() as demo:
17
  text_input = gr.Textbox(label="Enter prompt")
18
  gallery = gr.Gallery(label="Generated Images", columns=6, rows=2, object_fit="contain", height="auto")
19
-
20
  button = gr.Button("Diffusion Lens") # Create a button with the label 'Diffusion Lens'
21
- all_images = [] # Initialize a list to store all images outside the function
22
-
23
- # Bind the button click to the generate_images function
24
- button.click(fn=generate_images, inputs=[text_input, gr.State(all_images)], outputs=gallery)
25
 
26
- # text_input.change(fn=generate_images, inputs=text_input, outputs=gallery)
 
27
 
28
  demo.launch()
29
 
30
 
31
- # def display_images(images):
32
- # # Prepare images for display
33
- # return [gr.Image(image) for image in images]
 
 
34
 
35
- # def get_prompt(prompt):
36
- # print('prompt:', prompt)
37
- # return prompt
38
 
39
- # def generate_images(prompt):
40
  # print('calling diffusion lens')
41
- # for skip_layers in range(23, 0, -1):
 
42
  # images = get_images(prompt, skip_layers=skip_layers)
43
- # yield images[0] # Yield each image as soon as it's ready
44
- # # yield gr.Image(images[0]) # Yield each image as soon as it's ready
45
 
46
  # with gr.Blocks() as demo:
47
- # text_input = gr.Interface(fn=generate_images, inputs="text", outputs="image")
48
- # demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from diffusion_lens import get_images
3
 
4
+ def generate_images(prompt, _):
 
 
 
 
5
  print('calling diffusion lens')
6
+ all_images = [] # Initialize a list to store all images
7
  for skip_layers in range(11, -1, -1):
8
  images = get_images(prompt, skip_layers=skip_layers)
9
+ all_images.append(images[0]) # Add the new image to the list
10
+ yield all_images # Yield the list of all images after each new image is added
11
 
12
  with gr.Blocks() as demo:
13
  text_input = gr.Textbox(label="Enter prompt")
14
  gallery = gr.Gallery(label="Generated Images", columns=6, rows=2, object_fit="contain", height="auto")
 
15
  button = gr.Button("Diffusion Lens") # Create a button with the label 'Diffusion Lens'
 
 
 
 
16
 
17
+ # Use the button to trigger the generate_images function
18
+ button.click(fn=generate_images, inputs=[text_input, gr.State(None)], outputs=gallery)
19
 
20
  demo.launch()
21
 
22
 
23
+ # import gradio as gr
24
+ # from diffusion_lens import get_images
25
+
26
+
27
+
28
 
 
 
 
29
 
30
+ # def generate_images(prompt, all_images):
31
  # print('calling diffusion lens')
32
+ # # all_images = [] # Initialize a list to store all images
33
+ # for skip_layers in range(11, -1, -1):
34
  # images = get_images(prompt, skip_layers=skip_layers)
35
+ # all_images.append(images[0]) # (images[0], f'layer_{12 - skip_layers}')) # Add the new image to the list
36
+ # yield all_images # Yield the list of all images
37
 
38
  # with gr.Blocks() as demo:
39
+ # text_input = gr.Textbox(label="Enter prompt")
40
+ # gallery = gr.Gallery(label="Generated Images", columns=6, rows=2, object_fit="contain", height="auto")
41
+
42
+ # button = gr.Button("Diffusion Lens") # Create a button with the label 'Diffusion Lens'
43
+ # all_images = [] # Initialize a list to store all images outside the function
44
+
45
+ # # Bind the button click to the generate_images function
46
+ # button.click(fn=generate_images, inputs=[text_input, gr.State(all_images)], outputs=gallery)
47
+
48
+ # # text_input.change(fn=generate_images, inputs=text_input, outputs=gallery)
49
+
50
+ # demo.launch()
51
+
52
+
53
+ # # def display_images(images):
54
+ # # # Prepare images for display
55
+ # # return [gr.Image(image) for image in images]
56
+
57
+ # # def get_prompt(prompt):
58
+ # # print('prompt:', prompt)
59
+ # # return prompt
60
+
61
+ # # def generate_images(prompt):
62
+ # # print('calling diffusion lens')
63
+ # # for skip_layers in range(23, 0, -1):
64
+ # # images = get_images(prompt, skip_layers=skip_layers)
65
+ # # yield images[0] # Yield each image as soon as it's ready
66
+ # # # yield gr.Image(images[0]) # Yield each image as soon as it's ready
67
+
68
+ # # with gr.Blocks() as demo:
69
+ # # text_input = gr.Interface(fn=generate_images, inputs="text", outputs="image")
70
+ # # demo.launch()