Spaces:
Runtime error
Runtime error
Stack images horizontally
Browse files
app.py
CHANGED
@@ -37,19 +37,17 @@ def process_image(image):
|
|
37 |
context = torch.tensor(context).to(device)
|
38 |
output = model.generate(input_ids=context, max_length=n_px*n_px + 1, temperature=1.0, do_sample=True, top_k=40)
|
39 |
|
40 |
-
# decode back to images
|
41 |
samples = output[:,1:].cpu().detach().numpy()
|
42 |
-
samples_img = [np.reshape(np.rint(127.5 * (clusters[s] + 1.0)), [n_px, n_px, 3]).astype(np.uint8) for s in samples]
|
43 |
|
44 |
-
#
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
plt.imsave(fname=fname, arr=samples_img[i], format='png')
|
50 |
-
completions.append(fname)
|
51 |
|
52 |
-
return
|
53 |
|
54 |
title = "Interactive demo: ImageGPT"
|
55 |
description = "Demo for OpenAI's ImageGPT: Generative Pretraining from Pixels. To use it, simply upload an image or use the example image below and click 'submit'. Results will show up in a few seconds."
|
@@ -58,7 +56,7 @@ examples =[["image_0.png"]]
|
|
58 |
|
59 |
iface = gr.Interface(fn=process_image,
|
60 |
inputs=gr.inputs.Image(type="pil"),
|
61 |
-
outputs=
|
62 |
title=title,
|
63 |
description=description,
|
64 |
article=article,
|
|
|
37 |
context = torch.tensor(context).to(device)
|
38 |
output = model.generate(input_ids=context, max_length=n_px*n_px + 1, temperature=1.0, do_sample=True, top_k=40)
|
39 |
|
40 |
+
# decode back to images (convert color cluster tokens back to pixels)
|
41 |
samples = output[:,1:].cpu().detach().numpy()
|
42 |
+
samples_img = [np.reshape(np.rint(127.5 * (clusters[s] + 1.0)), [n_px, n_px, 3]).astype(np.uint8) for s in samples]
|
43 |
|
44 |
+
# stack images horizontally
|
45 |
+
result = np.hstack(samples_img)
|
46 |
+
|
47 |
+
# return as PIL Image
|
48 |
+
completion = Image.fromarray(result)
|
|
|
|
|
49 |
|
50 |
+
return completion
|
51 |
|
52 |
title = "Interactive demo: ImageGPT"
|
53 |
description = "Demo for OpenAI's ImageGPT: Generative Pretraining from Pixels. To use it, simply upload an image or use the example image below and click 'submit'. Results will show up in a few seconds."
|
|
|
56 |
|
57 |
iface = gr.Interface(fn=process_image,
|
58 |
inputs=gr.inputs.Image(type="pil"),
|
59 |
+
outputs=gr.outputs.Image(type="pil"),
|
60 |
title=title,
|
61 |
description=description,
|
62 |
article=article,
|