Rahul8827 commited on
Commit
9c7aa2c
·
1 Parent(s): 136c793

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -10,6 +10,17 @@ from glide_text2im.model_creation import (
10
  )
11
  has_cuda = th.cuda.is_available()
12
  device = th.device('cpu' if not has_cuda else 'cuda')
 
 
 
 
 
 
 
 
 
 
 
13
  # Create upsampler model.
14
  options_up = model_and_diffusion_defaults_upsampler()
15
  options_up['use_fp16'] = has_cuda
@@ -27,13 +38,14 @@ def show_images(batch: th.Tensor):
27
  reshaped = scaled.permute(2, 0, 3, 1).reshape([batch.shape[2], -1, 3])
28
  display(Image.fromarray(reshaped.numpy()))
29
  # Sampling parameters
30
- prompt = ""
31
  batch_size = 1
32
  guidance_scale = 3.0
33
 
34
  # Tune this parameter to control the sharpness of 256x256 images.
35
  # A value of 1.0 is sharper, but sometimes results in grainy artifacts.
36
  upsample_temp = 0.997
 
37
  import gradio as gr
38
  def generate_upsampled_image_from_text(prompt):
39
  # Set the prompt text
@@ -82,5 +94,5 @@ def generate_upsampled_image_from_text(prompt):
82
 
83
  # Show the output
84
  show_images(up_samples)
85
- demo = gr.Interface(fn =generate_upsampled_image_from_text,inputs ="text",outputs ="image")
86
- demo.launch()
 
10
  )
11
  has_cuda = th.cuda.is_available()
12
  device = th.device('cpu' if not has_cuda else 'cuda')
13
+ # Create base model.
14
+ options = model_and_diffusion_defaults()
15
+ options['use_fp16'] = has_cuda
16
+ options['timestep_respacing'] = '100' # use 100 diffusion steps for fast sampling
17
+ model, diffusion = create_model_and_diffusion(**options)
18
+ model.eval()
19
+ if has_cuda:
20
+ model.convert_to_fp16()
21
+ model.to(device)
22
+ model.load_state_dict(load_checkpoint('base', device))
23
+ print('total base parameters', sum(x.numel() for x in model.parameters()))
24
  # Create upsampler model.
25
  options_up = model_and_diffusion_defaults_upsampler()
26
  options_up['use_fp16'] = has_cuda
 
38
  reshaped = scaled.permute(2, 0, 3, 1).reshape([batch.shape[2], -1, 3])
39
  display(Image.fromarray(reshaped.numpy()))
40
  # Sampling parameters
41
+ prompt = "an oil painting of a corgi"
42
  batch_size = 1
43
  guidance_scale = 3.0
44
 
45
  # Tune this parameter to control the sharpness of 256x256 images.
46
  # A value of 1.0 is sharper, but sometimes results in grainy artifacts.
47
  upsample_temp = 0.997
48
+
49
  import gradio as gr
50
  def generate_upsampled_image_from_text(prompt):
51
  # Set the prompt text
 
94
 
95
  # Show the output
96
  show_images(up_samples)
97
+ demo = gr.Interface(fn =generate_upsampled_image_from_text ="text",outputs ="image")
98
+ demo.launch()