ysharma HF staff commited on
Commit
ab8afd8
1 Parent(s): 1a81f89
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -107,7 +107,7 @@ clip_model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32', pr
107
  def run(prompt, steps, width, height, images, scale):
108
  opt = argparse.Namespace(
109
  prompt = prompt,
110
- outdir='./outputs',
111
  ddim_steps = int(steps),
112
  ddim_eta = 1,
113
  n_iter = 1,
@@ -124,15 +124,15 @@ def run(prompt, steps, width, height, images, scale):
124
  else:
125
  sampler = DDIMSampler(model)
126
 
127
- os.makedirs(opt.outdir, exist_ok=True)
128
- outpath = opt.outdir
129
 
130
  prompt = opt.prompt
131
 
132
 
133
- sample_path = os.path.join(outpath, "samples")
134
- os.makedirs(sample_path, exist_ok=True)
135
- base_count = len(os.listdir(sample_path))
136
 
137
  all_samples=list()
138
  all_samples_images=list()
@@ -171,7 +171,7 @@ def run(prompt, steps, width, height, images, scale):
171
  else:
172
  return(None,None,"Sorry, potential NSFW content was detected on your outputs by our NSFW detection model. Try again with different prompts. If you feel your prompt was not supposed to give NSFW outputs, this may be due to a bias in the model. Read more about biases in the Biases Acknowledgment section below.")
173
  #Image.fromarray(x_sample.astype(np.uint8)).save(os.path.join(sample_path, f"{base_count:04}.png"))
174
- base_count += 1
175
  all_samples.append(x_samples_ddim)
176
 
177
 
@@ -182,7 +182,7 @@ def run(prompt, steps, width, height, images, scale):
182
  # to image
183
  grid = 255. * rearrange(grid, 'c h w -> h w c').cpu().numpy()
184
 
185
- Image.fromarray(grid.astype(np.uint8)).save(os.path.join(outpath, f'{prompt.replace(" ", "-")}.png'))
186
  #return(Image.fromarray(grid.astype(np.uint8)),all_samples_images,None)
187
  return Image.fromarray(grid.astype(np.uint8))
188
 
@@ -221,7 +221,7 @@ app = gr.Interface(fn=engine,
221
  #live=True,
222
  description="Takes a text as input and reads it out to you.",
223
  outputs=[#gr.outputs.Textbox(type="auto", label="Text"),gr.outputs.Audio(type="file", label="Speech Answer"),
224
- gr.outputs.Image(type="auto", label="output image"),],
225
  examples=["On April 17th Sunday George celebrated Easter. He is staying at Empire State building with his parents. He is a citizen of Canada and speaks English and French fluently. His role model is former president Obama. He got 1000 dollar from his mother to visit Disney World and to buy new iPhone mobile. George likes watching Game of Thrones."]
226
  ).launch(debug=True)
227
 
 
107
  def run(prompt, steps, width, height, images, scale):
108
  opt = argparse.Namespace(
109
  prompt = prompt,
110
+ ###outdir='./outputs',
111
  ddim_steps = int(steps),
112
  ddim_eta = 1,
113
  n_iter = 1,
 
124
  else:
125
  sampler = DDIMSampler(model)
126
 
127
+ ###os.makedirs(opt.outdir, exist_ok=True)
128
+ ###outpath = opt.outdir
129
 
130
  prompt = opt.prompt
131
 
132
 
133
+ ###sample_path = os.path.join(outpath, "samples")
134
+ ###os.makedirs(sample_path, exist_ok=True)
135
+ ###base_count = len(os.listdir(sample_path))
136
 
137
  all_samples=list()
138
  all_samples_images=list()
 
171
  else:
172
  return(None,None,"Sorry, potential NSFW content was detected on your outputs by our NSFW detection model. Try again with different prompts. If you feel your prompt was not supposed to give NSFW outputs, this may be due to a bias in the model. Read more about biases in the Biases Acknowledgment section below.")
173
  #Image.fromarray(x_sample.astype(np.uint8)).save(os.path.join(sample_path, f"{base_count:04}.png"))
174
+ ###base_count += 1
175
  all_samples.append(x_samples_ddim)
176
 
177
 
 
182
  # to image
183
  grid = 255. * rearrange(grid, 'c h w -> h w c').cpu().numpy()
184
 
185
+ ###Image.fromarray(grid.astype(np.uint8)).save(os.path.join(outpath, f'{prompt.replace(" ", "-")}.png'))
186
  #return(Image.fromarray(grid.astype(np.uint8)),all_samples_images,None)
187
  return Image.fromarray(grid.astype(np.uint8))
188
 
 
221
  #live=True,
222
  description="Takes a text as input and reads it out to you.",
223
  outputs=[#gr.outputs.Textbox(type="auto", label="Text"),gr.outputs.Audio(type="file", label="Speech Answer"),
224
+ gr.outputs.Image(type="auto", label="output image")],
225
  examples=["On April 17th Sunday George celebrated Easter. He is staying at Empire State building with his parents. He is a citizen of Canada and speaks English and French fluently. His role model is former president Obama. He got 1000 dollar from his mother to visit Disney World and to buy new iPhone mobile. George likes watching Game of Thrones."]
226
  ).launch(debug=True)
227