Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,14 @@ def update_imgbox(choices):
|
|
28 |
choices_plus = extend_choices(choices)
|
29 |
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def gen_fn(model_str, prompt, negative_prompt=None, image_style="Default"):
|
32 |
if model_str == 'NA':
|
33 |
return None
|
@@ -35,15 +43,7 @@ def gen_fn(model_str, prompt, negative_prompt=None, image_style="Default"):
|
|
35 |
if negative_prompt:
|
36 |
modified_prompt += f", not {negative_prompt}"
|
37 |
image = models_load[model_str](modified_prompt)
|
38 |
-
|
39 |
-
# Save image as .jpg
|
40 |
-
if image is not None:
|
41 |
-
img = Image.fromarray(image)
|
42 |
-
img_byte_arr = io.BytesIO()
|
43 |
-
img.save(img_byte_arr, format='JPEG')
|
44 |
-
img_byte_arr = img_byte_arr.getvalue()
|
45 |
-
return img_byte_arr
|
46 |
-
return None
|
47 |
|
48 |
with gr.Blocks() as demo:
|
49 |
with gr.Tab('The Dream'):
|
|
|
28 |
choices_plus = extend_choices(choices)
|
29 |
return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
|
30 |
|
31 |
+
def save_image_as_jpg(image):
|
32 |
+
if image:
|
33 |
+
image = Image.open(io.BytesIO(image))
|
34 |
+
img_byte_arr = io.BytesIO()
|
35 |
+
image.save(img_byte_arr, format='JPEG')
|
36 |
+
return img_byte_arr.getvalue()
|
37 |
+
return None
|
38 |
+
|
39 |
def gen_fn(model_str, prompt, negative_prompt=None, image_style="Default"):
|
40 |
if model_str == 'NA':
|
41 |
return None
|
|
|
43 |
if negative_prompt:
|
44 |
modified_prompt += f", not {negative_prompt}"
|
45 |
image = models_load[model_str](modified_prompt)
|
46 |
+
return save_image_as_jpg(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
with gr.Blocks() as demo:
|
49 |
with gr.Tab('The Dream'):
|