Spaces:
Runtime error
Runtime error
Ahsen Khaliq
commited on
Commit
Β·
821b58d
1
Parent(s):
67bd1fa
Update app.py
Browse files
app.py
CHANGED
@@ -24,9 +24,7 @@ import imageio
|
|
24 |
from PIL import ImageFile, Image
|
25 |
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
26 |
import gradio as gr
|
27 |
-
|
28 |
torch.hub.download_url_to_file('https://i.imgur.com/WEHmKef.jpg', 'gpu.jpg')
|
29 |
-
|
30 |
def sinc(x):
|
31 |
return torch.where(x != 0, torch.sin(math.pi * x) / (math.pi * x), x.new_ones([]))
|
32 |
def lanczos(x, a):
|
@@ -166,8 +164,6 @@ def resize_image(image, out_size):
|
|
166 |
area = min(image.size[0] * image.size[1], out_size[0] * out_size[1])
|
167 |
size = round((area * ratio)**0.5), round((area / ratio)**0.5)
|
168 |
return image.resize(size, Image.LANCZOS)
|
169 |
-
|
170 |
-
|
171 |
model_name = "vqgan_imagenet_f16_16384"
|
172 |
images_interval = 50
|
173 |
width = 280
|
@@ -193,11 +189,10 @@ device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
|
193 |
print('Using device:', device)
|
194 |
model = load_vqgan_model(args.vqgan_config, args.vqgan_checkpoint).to(device)
|
195 |
perceptor = clip.load(args.clip_model, jit=False)[0].eval().requires_grad_(False).to(device)
|
196 |
-
|
197 |
-
def inference(text, seed, step_size):
|
198 |
texts = text
|
199 |
target_images = ""
|
200 |
-
max_iterations =
|
201 |
model_names={"vqgan_imagenet_f16_16384": 'ImageNet 16384',"vqgan_imagenet_f16_1024":"ImageNet 1024", 'vqgan_openimages_f16_8192':'OpenImages 8912',
|
202 |
"wikiart_1024":"WikiArt 1024", "wikiart_16384":"WikiArt 16384", "coco":"COCO-Stuff", "faceshq":"FacesHQ", "sflckr":"S-FLCKR"}
|
203 |
name_model = model_names[model_name]
|
@@ -334,31 +329,25 @@ def inference(text, seed, step_size):
|
|
334 |
except KeyboardInterrupt:
|
335 |
pass
|
336 |
return image
|
337 |
-
|
338 |
inferences_running = 0
|
339 |
-
|
340 |
def load_image( infilename ) :
|
341 |
img = Image.open( infilename )
|
342 |
img.load()
|
343 |
data = np.asarray( img, dtype="int32" )
|
344 |
return data
|
345 |
-
|
346 |
-
def throttled_inference(text, seed, step_size):
|
347 |
global inferences_running
|
348 |
current = inferences_running
|
349 |
if current >= 2:
|
350 |
print(f"Rejected inference when we already had {current} running")
|
351 |
return load_image("./gpu.jpg")
|
352 |
-
|
353 |
print(f"Inference starting when we already had {current} running")
|
354 |
inferences_running += 1
|
355 |
try:
|
356 |
-
return inference(text, seed, step_size)
|
357 |
finally:
|
358 |
print("Inference finished")
|
359 |
inferences_running -= 1
|
360 |
-
|
361 |
-
|
362 |
title = "VQGAN + CLIP"
|
363 |
description = "Gradio demo for VQGAN + CLIP. To use it, simply add your text, or click one of the examples to load them. Read more at the links below. Please click submit only once. Results will show up in under a minute."
|
364 |
article = "<p style='text-align: center'>Originally made by Katherine Crowson (https://github.com/crowsonkb, https://twitter.com/RiversHaveWings). The original BigGAN+CLIP method was by https://twitter.com/advadnoun. Added some explanations and modifications by Eleiber#8347, pooling trick by Crimeacs#8222 (https://twitter.com/EarthML1) and the GUI was made with the help of Abulafia#3734. | <a href='https://colab.research.google.com/drive/1ZAus_gn2RhTZWzOWUpPERNC0Q8OhZRTZ'>Colab</a> | <a href='https://github.com/CompVis/taming-transformers'>Taming Transformers Github Repo</a> | <a href='https://github.com/openai/CLIP'>CLIP Github Repo</a> | Special thanks to BoneAmputee (https://twitter.com/BoneAmputee) for suggestions and advice</p>"
|
@@ -366,15 +355,16 @@ gr.Interface(
|
|
366 |
throttled_inference,
|
367 |
[gr.inputs.Textbox(label="Input"),
|
368 |
gr.inputs.Number(default=42, label="seed"),
|
369 |
-
gr.inputs.Slider(minimum=0.1, maximum=0.9, default=0.23, label='step size')
|
|
|
370 |
],
|
371 |
gr.outputs.Image(type="numpy", label="Output"),
|
372 |
title=title,
|
373 |
description=description,
|
374 |
article=article,
|
375 |
examples=[
|
376 |
-
['a garden by james gurney',42,0.23],
|
377 |
-
['coral reef city artstationHQ',1000,0.6],
|
378 |
-
['a cabin in the mountains unreal engine',98,0.3]
|
379 |
]
|
380 |
).launch(debug=True)
|
|
|
24 |
from PIL import ImageFile, Image
|
25 |
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
26 |
import gradio as gr
|
|
|
27 |
torch.hub.download_url_to_file('https://i.imgur.com/WEHmKef.jpg', 'gpu.jpg')
|
|
|
28 |
def sinc(x):
|
29 |
return torch.where(x != 0, torch.sin(math.pi * x) / (math.pi * x), x.new_ones([]))
|
30 |
def lanczos(x, a):
|
|
|
164 |
area = min(image.size[0] * image.size[1], out_size[0] * out_size[1])
|
165 |
size = round((area * ratio)**0.5), round((area / ratio)**0.5)
|
166 |
return image.resize(size, Image.LANCZOS)
|
|
|
|
|
167 |
model_name = "vqgan_imagenet_f16_16384"
|
168 |
images_interval = 50
|
169 |
width = 280
|
|
|
189 |
print('Using device:', device)
|
190 |
model = load_vqgan_model(args.vqgan_config, args.vqgan_checkpoint).to(device)
|
191 |
perceptor = clip.load(args.clip_model, jit=False)[0].eval().requires_grad_(False).to(device)
|
192 |
+
def inference(text, seed, step_size, max_iterations):
|
|
|
193 |
texts = text
|
194 |
target_images = ""
|
195 |
+
max_iterations = max_iterations
|
196 |
model_names={"vqgan_imagenet_f16_16384": 'ImageNet 16384',"vqgan_imagenet_f16_1024":"ImageNet 1024", 'vqgan_openimages_f16_8192':'OpenImages 8912',
|
197 |
"wikiart_1024":"WikiArt 1024", "wikiart_16384":"WikiArt 16384", "coco":"COCO-Stuff", "faceshq":"FacesHQ", "sflckr":"S-FLCKR"}
|
198 |
name_model = model_names[model_name]
|
|
|
329 |
except KeyboardInterrupt:
|
330 |
pass
|
331 |
return image
|
|
|
332 |
inferences_running = 0
|
|
|
333 |
def load_image( infilename ) :
|
334 |
img = Image.open( infilename )
|
335 |
img.load()
|
336 |
data = np.asarray( img, dtype="int32" )
|
337 |
return data
|
338 |
+
def throttled_inference(text, seed, step_size, max_iterations):
|
|
|
339 |
global inferences_running
|
340 |
current = inferences_running
|
341 |
if current >= 2:
|
342 |
print(f"Rejected inference when we already had {current} running")
|
343 |
return load_image("./gpu.jpg")
|
|
|
344 |
print(f"Inference starting when we already had {current} running")
|
345 |
inferences_running += 1
|
346 |
try:
|
347 |
+
return inference(text, seed, step_size, max_iterations)
|
348 |
finally:
|
349 |
print("Inference finished")
|
350 |
inferences_running -= 1
|
|
|
|
|
351 |
title = "VQGAN + CLIP"
|
352 |
description = "Gradio demo for VQGAN + CLIP. To use it, simply add your text, or click one of the examples to load them. Read more at the links below. Please click submit only once. Results will show up in under a minute."
|
353 |
article = "<p style='text-align: center'>Originally made by Katherine Crowson (https://github.com/crowsonkb, https://twitter.com/RiversHaveWings). The original BigGAN+CLIP method was by https://twitter.com/advadnoun. Added some explanations and modifications by Eleiber#8347, pooling trick by Crimeacs#8222 (https://twitter.com/EarthML1) and the GUI was made with the help of Abulafia#3734. | <a href='https://colab.research.google.com/drive/1ZAus_gn2RhTZWzOWUpPERNC0Q8OhZRTZ'>Colab</a> | <a href='https://github.com/CompVis/taming-transformers'>Taming Transformers Github Repo</a> | <a href='https://github.com/openai/CLIP'>CLIP Github Repo</a> | Special thanks to BoneAmputee (https://twitter.com/BoneAmputee) for suggestions and advice</p>"
|
|
|
355 |
throttled_inference,
|
356 |
[gr.inputs.Textbox(label="Input"),
|
357 |
gr.inputs.Number(default=42, label="seed"),
|
358 |
+
gr.inputs.Slider(minimum=0.1, maximum=0.9, default=0.23, label='step size'),
|
359 |
+
gr.inputs.Slider(minimum=100, maximum=150, default=100, label='max iterations', step=1),
|
360 |
],
|
361 |
gr.outputs.Image(type="numpy", label="Output"),
|
362 |
title=title,
|
363 |
description=description,
|
364 |
article=article,
|
365 |
examples=[
|
366 |
+
['a garden by james gurney',42,0.23, 100],
|
367 |
+
['coral reef city artstationHQ',1000,0.6, 110],
|
368 |
+
['a cabin in the mountains unreal engine',98,0.3, 120]
|
369 |
]
|
370 |
).launch(debug=True)
|