Ahsen Khaliq commited on
Commit
f619e7d
1 Parent(s): 46e5614

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -85,7 +85,7 @@ model_config.update({
85
  'class_cond': False,
86
  'diffusion_steps': 1000,
87
  'rescale_timesteps': True,
88
- 'timestep_respacing': '300', # Modify this value to decrease the number of
89
  # timesteps.
90
  'image_size': 256,
91
  'learn_sigma': True,
@@ -114,12 +114,12 @@ normalize = transforms.Normalize(mean=[0.48145466, 0.4578275, 0.40821073],
114
  std=[0.26862954, 0.26130258, 0.27577711])
115
  lpips_model = lpips.LPIPS(net='vgg').to(device)
116
 
117
- def inference(text, init_image, skip_timesteps):
118
  all_frames = []
119
  prompts = [text]
120
  image_prompts = []
121
  batch_size = 1
122
- clip_guidance_scale = 1000 # Controls how much the image should look like the prompt.
123
  tv_scale = 150 # Controls the smoothness of the final output.
124
  range_scale = 50 # Controls how far out of range RGB values are allowed to be.
125
  cutn = 16
@@ -208,7 +208,7 @@ def inference(text, init_image, skip_timesteps):
208
  all_frames.append(img)
209
  tqdm.write(f'Batch {i}, step {j}, output {k}:')
210
  #display.display(display.Image(filename))
211
- writer = imageio.get_writer('video.mp4', fps=20)
212
  for im in all_frames:
213
  writer.append_data(np.array(im))
214
  writer.close()
@@ -217,6 +217,6 @@ def inference(text, init_image, skip_timesteps):
217
  title = "CLIP Guided Diffusion HQ"
218
  description = "Gradio demo for CLIP Guided Diffusion. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
219
  article = "<p style='text-align: center'> By Katherine Crowson (https://github.com/crowsonkb, https://twitter.com/RiversHaveWings). It uses OpenAI's 256x256 unconditional ImageNet diffusion model (https://github.com/openai/guided-diffusion) together with CLIP (https://github.com/openai/CLIP) to connect text prompts with images. | <a href='https://colab.research.google.com/drive/12a_Wrfi2_gwwAuN3VvMTwVMz9TfqctNj' target='_blank'>Colab</a></p>"
220
- iface = gr.Interface(inference, inputs=["text",gr.inputs.Image(type="file", label='initial image (optional)', optional=True),gr.inputs.Slider(minimum=0, maximum=150, step=1, default=0, label="skip_timesteps")], outputs=["image","video"], title=title, description=description, article=article, examples=[["coral reef city by artistation artists"]],
221
  enable_queue=True)
222
  iface.launch()
 
85
  'class_cond': False,
86
  'diffusion_steps': 1000,
87
  'rescale_timesteps': True,
88
+ 'timestep_respacing': '90', # Modify this value to decrease the number of
89
  # timesteps.
90
  'image_size': 256,
91
  'learn_sigma': True,
 
114
  std=[0.26862954, 0.26130258, 0.27577711])
115
  lpips_model = lpips.LPIPS(net='vgg').to(device)
116
 
117
+ def inference(text, init_image, skip_timesteps, clip_guidance_scale):
118
  all_frames = []
119
  prompts = [text]
120
  image_prompts = []
121
  batch_size = 1
122
+ clip_guidance_scale = clip_guidance_scale # Controls how much the image should look like the prompt.
123
  tv_scale = 150 # Controls the smoothness of the final output.
124
  range_scale = 50 # Controls how far out of range RGB values are allowed to be.
125
  cutn = 16
 
208
  all_frames.append(img)
209
  tqdm.write(f'Batch {i}, step {j}, output {k}:')
210
  #display.display(display.Image(filename))
211
+ writer = imageio.get_writer('video.mp4', fps=5)
212
  for im in all_frames:
213
  writer.append_data(np.array(im))
214
  writer.close()
 
217
  title = "CLIP Guided Diffusion HQ"
218
  description = "Gradio demo for CLIP Guided Diffusion. To use it, simply add your text, or click one of the examples to load them. Read more at the links below."
219
  article = "<p style='text-align: center'> By Katherine Crowson (https://github.com/crowsonkb, https://twitter.com/RiversHaveWings). It uses OpenAI's 256x256 unconditional ImageNet diffusion model (https://github.com/openai/guided-diffusion) together with CLIP (https://github.com/openai/CLIP) to connect text prompts with images. | <a href='https://colab.research.google.com/drive/12a_Wrfi2_gwwAuN3VvMTwVMz9TfqctNj' target='_blank'>Colab</a></p>"
220
+ iface = gr.Interface(inference, inputs=["text",gr.inputs.Image(type="file", label='initial image (optional)', optional=True),gr.inputs.Slider(minimum=0, maximum=45, step=1, default=0, label="skip_timesteps"), gr.inputs.Slider(minimum=0, maximum=1000, step=1, default=700, label="clip guidance scale (Controls how much the image should look like the prompt.)")], outputs=["image","video"], title=title, description=description, article=article, examples=[["coral reef city by artistation artists"]],
221
  enable_queue=True)
222
  iface.launch()