Spaces:
Running
Running
fixed upscaler
Browse files
frontend/webui/text_to_image_ui.py
CHANGED
|
@@ -13,8 +13,16 @@ from frontend.utils import enable_openvino_controls
|
|
| 13 |
from scipy.ndimage import zoom
|
| 14 |
import numpy as np
|
| 15 |
from PIL import Image
|
| 16 |
-
from super_image import CarnModel,ImageLoader
|
| 17 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
random_enabled = True
|
| 20 |
|
|
@@ -23,7 +31,8 @@ previous_width = 0
|
|
| 23 |
previous_height = 0
|
| 24 |
previous_model_id = ""
|
| 25 |
previous_num_of_images = 0
|
| 26 |
-
upscaler = CarnModel.from_pretrained(
|
|
|
|
| 27 |
|
| 28 |
def generate_text_to_image(
|
| 29 |
prompt,
|
|
@@ -79,14 +88,11 @@ def generate_text_to_image(
|
|
| 79 |
previous_num_of_images = 1
|
| 80 |
out_images = []
|
| 81 |
for image in images:
|
| 82 |
-
#out_images.append(image.resize((768, 768),resample=Image.LANCZOS))
|
| 83 |
in_image = ImageLoader.load_image(image)
|
| 84 |
up_image = upscaler(in_image)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
up_image = cv2.cvtColor(up_image, cv2.COLOR_BGR2RGB)
|
| 88 |
-
out_images.append(Image.fromarray(up_image))
|
| 89 |
-
|
| 90 |
return out_images
|
| 91 |
|
| 92 |
|
|
|
|
| 13 |
from scipy.ndimage import zoom
|
| 14 |
import numpy as np
|
| 15 |
from PIL import Image
|
| 16 |
+
from super_image import CarnModel, ImageLoader
|
| 17 |
+
from torchvision import transforms
|
| 18 |
+
|
| 19 |
+
transform_image = transforms.ToPILImage()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def tensor2img(tensor):
|
| 23 |
+
tensor = tensor.squeeze(0).cpu().clamp(0, 1)
|
| 24 |
+
return transform_image(tensor)
|
| 25 |
+
|
| 26 |
|
| 27 |
random_enabled = True
|
| 28 |
|
|
|
|
| 31 |
previous_height = 0
|
| 32 |
previous_model_id = ""
|
| 33 |
previous_num_of_images = 0
|
| 34 |
+
upscaler = CarnModel.from_pretrained("eugenesiow/carn-bam", scale=2)
|
| 35 |
+
|
| 36 |
|
| 37 |
def generate_text_to_image(
|
| 38 |
prompt,
|
|
|
|
| 88 |
previous_num_of_images = 1
|
| 89 |
out_images = []
|
| 90 |
for image in images:
|
| 91 |
+
# out_images.append(image.resize((768, 768),resample=Image.LANCZOS))
|
| 92 |
in_image = ImageLoader.load_image(image)
|
| 93 |
up_image = upscaler(in_image)
|
| 94 |
+
out_images.append(tensor2img(up_image))
|
| 95 |
+
|
|
|
|
|
|
|
|
|
|
| 96 |
return out_images
|
| 97 |
|
| 98 |
|