awacke1 commited on
Commit
3043030
1 Parent(s): 70f0c27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -76,6 +76,12 @@ def encode_image(image):
76
  buffered = BytesIO()
77
  #image.save(buffered, format="PNG")
78
  return base64.b64encode(buffered.getvalue()).decode()
 
 
 
 
 
 
79
 
80
  def predict(prompt, guidance, steps, seed=1231231):
81
  generator = torch.manual_seed(seed)
@@ -151,7 +157,25 @@ with gr.Blocks(css=css) as demo:
151
  )
152
  generate_bt = gr.Button("Generate", scale=1)
153
 
 
154
  image = gr.Image(type="filepath")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  with gr.Accordion("Advanced options", open=False):
156
  guidance = gr.Slider(
157
  label="Guidance", minimum=0.0, maximum=5, value=0.3, step=0.001
@@ -186,6 +210,7 @@ with gr.Blocks(css=css) as demo:
186
 
187
  inputs = [prompt, guidance, steps, seed]
188
  generate_bt.click(fn=predict, inputs=inputs, outputs=image, show_progress=False)
 
189
  prompt.input(fn=predict, inputs=inputs, outputs=image, show_progress=False)
190
  guidance.change(fn=predict, inputs=inputs, outputs=image, show_progress=False)
191
  steps.change(fn=predict, inputs=inputs, outputs=image, show_progress=False)
 
76
  buffered = BytesIO()
77
  #image.save(buffered, format="PNG")
78
  return base64.b64encode(buffered.getvalue()).decode()
79
+
80
+ def fake_gan():
81
+ base_dir = os.getcwd() # Get the current base directory
82
+ img_files = [file for file in os.listdir(base_dir) if file.lower().endswith((".png", ".jpg", ".jpeg"))] # List all files ending with ".jpg" or ".jpeg"
83
+ images = [(random.choice(img_files), os.path.splitext(file)[0]) for file in img_files]
84
+ return images
85
 
86
  def predict(prompt, guidance, steps, seed=1231231):
87
  generator = torch.manual_seed(seed)
 
157
  )
158
  generate_bt = gr.Button("Generate", scale=1)
159
 
160
+ # Image Result from last prompt
161
  image = gr.Image(type="filepath")
162
+
163
+ # Gallery
164
+ with gr.Row(variant="compact"):
165
+ text = gr.Textbox(
166
+ label="Image Sets",
167
+ show_label=False,
168
+ max_lines=1,
169
+ placeholder="Enter your prompt",
170
+ ).style(
171
+ container=False,
172
+ )
173
+ btn = gr.Button("Generate image").style(full_width=False)
174
+
175
+ gallery = gr.Gallery(
176
+ label="Generated images", show_label=False, elem_id="gallery"
177
+ ).style(grid=[2], height="auto")
178
+
179
  with gr.Accordion("Advanced options", open=False):
180
  guidance = gr.Slider(
181
  label="Guidance", minimum=0.0, maximum=5, value=0.3, step=0.001
 
210
 
211
  inputs = [prompt, guidance, steps, seed]
212
  generate_bt.click(fn=predict, inputs=inputs, outputs=image, show_progress=False)
213
+ btn.click(fake_gan, None, gallery)
214
  prompt.input(fn=predict, inputs=inputs, outputs=image, show_progress=False)
215
  guidance.change(fn=predict, inputs=inputs, outputs=image, show_progress=False)
216
  steps.change(fn=predict, inputs=inputs, outputs=image, show_progress=False)