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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -48
app.py CHANGED
@@ -1,70 +1,47 @@
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()
 
1
  import gradio as gr
2
  from diffusion_lens import get_images
3
 
4
+
5
+
6
+
7
+
8
+ def generate_images(prompt):
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
 
22
+ # Bind the button click to the generate_images function
23
+ # button.click(fn=generate_images, inputs=[text_input, gr.State(all_images)], outputs=gallery)
24
+
25
+ text_input.submit(fn=generate_images, inputs=text_input, outputs=gallery)
26
 
27
+ demo.launch()
28
 
29
 
30
+ # def display_images(images):
31
+ # # Prepare images for display
32
+ # return [gr.Image(image) for image in images]
33
 
34
+ # def get_prompt(prompt):
35
+ # print('prompt:', prompt)
36
+ # return prompt
37
 
38
+ # def generate_images(prompt):
39
  # print('calling diffusion lens')
40
+ # for skip_layers in range(23, 0, -1):
 
41
  # images = get_images(prompt, skip_layers=skip_layers)
42
+ # yield images[0] # Yield each image as soon as it's ready
43
+ # # yield gr.Image(images[0]) # Yield each image as soon as it's ready
44
 
45
  # with gr.Blocks() as demo:
46
+ # text_input = gr.Interface(fn=generate_images, inputs="text", outputs="image")
47
+ # demo.launch()