Spaces:
Runtime error
Runtime error
Freiburg-AI-Research
commited on
Commit
Β·
0e9b575
1
Parent(s):
29ba125
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ import gradio as gr
|
|
8 |
import base64
|
9 |
from io import BytesIO
|
10 |
# from fastapi import FastAPI
|
11 |
-
from PIL import ImageOps
|
12 |
from PIL import Image
|
13 |
import torch as th
|
14 |
|
@@ -113,13 +112,11 @@ print('total upsampler parameters', sum(x.numel() for x in model_up.parameters()
|
|
113 |
|
114 |
|
115 |
|
116 |
-
def get_images(batch: th.Tensor
|
117 |
""" Display a batch of images inline. """
|
118 |
scaled = ((batch + 1)*127.5).round().clamp(0,255).to(th.uint8).cpu()
|
119 |
reshaped = scaled.permute(2, 0, 3, 1).reshape([batch.shape[2], -1, 3])
|
120 |
-
|
121 |
-
image = ImageOps.fit(image, output_size, Image.ANTIALIAS)
|
122 |
-
return image
|
123 |
|
124 |
|
125 |
|
@@ -236,10 +233,9 @@ def sample(prompt):
|
|
236 |
)[:batch_size]
|
237 |
model_up.del_cache()
|
238 |
|
239 |
-
# Show the output
|
240 |
image = get_images(up_samples)
|
241 |
-
image = to_base64(image)
|
242 |
-
#return {"image": image}
|
243 |
return image
|
244 |
|
245 |
|
@@ -249,6 +245,8 @@ title = "Interactive demo: glide-text2im dermoscopic image generator"
|
|
249 |
description = "Demo for the Finetuned version of OpenAI's GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models. Please be aware that generation of the image will take up to 20 minutes, as CPU is used for the generation. Please cite our research paper with the title -Finetuning of GLIDE stable diffusion model for AI-based text-conditional image synthesis of dermoscopic images-"
|
250 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.10741'>GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models</a> | <a href='https://github.com/openai/glide-text2im/'>Official Repo</a></p>"
|
251 |
examples =["melanoma"]
|
|
|
|
|
252 |
|
253 |
iface = gr.Interface(fn=sample,
|
254 |
inputs=gr.inputs.Textbox(label='Which dermoscopic entity would you like to see? Choose one of the following one: "melanoma", "melanocytic nevi", "Actinic keratoses and intraepithelial carcinoma / Bowen disease, "benign keratosis-like lesions (solar lentigines / seborrheic keratoses and lichen-planus like keratoses", "basal cell carcinoma", "dermatofibroma", "vascular lesions"'),
|
@@ -257,5 +255,6 @@ iface = gr.Interface(fn=sample,
|
|
257 |
description=description,
|
258 |
article=article,
|
259 |
examples=examples,
|
|
|
260 |
enable_queue=True)
|
261 |
iface.launch(debug=True)
|
|
|
8 |
import base64
|
9 |
from io import BytesIO
|
10 |
# from fastapi import FastAPI
|
|
|
11 |
from PIL import Image
|
12 |
import torch as th
|
13 |
|
|
|
112 |
|
113 |
|
114 |
|
115 |
+
def get_images(batch: th.Tensor):
|
116 |
""" Display a batch of images inline. """
|
117 |
scaled = ((batch + 1)*127.5).round().clamp(0,255).to(th.uint8).cpu()
|
118 |
reshaped = scaled.permute(2, 0, 3, 1).reshape([batch.shape[2], -1, 3])
|
119 |
+
return Image.fromarray(reshaped.numpy())
|
|
|
|
|
120 |
|
121 |
|
122 |
|
|
|
233 |
)[:batch_size]
|
234 |
model_up.del_cache()
|
235 |
|
|
|
236 |
image = get_images(up_samples)
|
237 |
+
# image = to_base64(image)
|
238 |
+
# return {"image": image}
|
239 |
return image
|
240 |
|
241 |
|
|
|
245 |
description = "Demo for the Finetuned version of OpenAI's GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models. Please be aware that generation of the image will take up to 20 minutes, as CPU is used for the generation. Please cite our research paper with the title -Finetuning of GLIDE stable diffusion model for AI-based text-conditional image synthesis of dermoscopic images-"
|
246 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.10741'>GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models</a> | <a href='https://github.com/openai/glide-text2im/'>Official Repo</a></p>"
|
247 |
examples =["melanoma"]
|
248 |
+
css = ".output_image {height: 40rem !important; width: 100% !important;}"
|
249 |
+
|
250 |
|
251 |
iface = gr.Interface(fn=sample,
|
252 |
inputs=gr.inputs.Textbox(label='Which dermoscopic entity would you like to see? Choose one of the following one: "melanoma", "melanocytic nevi", "Actinic keratoses and intraepithelial carcinoma / Bowen disease, "benign keratosis-like lesions (solar lentigines / seborrheic keratoses and lichen-planus like keratoses", "basal cell carcinoma", "dermatofibroma", "vascular lesions"'),
|
|
|
255 |
description=description,
|
256 |
article=article,
|
257 |
examples=examples,
|
258 |
+
css=css,
|
259 |
enable_queue=True)
|
260 |
iface.launch(debug=True)
|