Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,9 @@ import spaces
|
|
2 |
import os
|
3 |
import torch
|
4 |
import random
|
|
|
|
|
|
|
5 |
from huggingface_hub import snapshot_download
|
6 |
from kolors.pipelines.pipeline_stable_diffusion_xl_chatglm_256 import StableDiffusionXLPipeline
|
7 |
from kolors.models.modeling_chatglm import ChatGLMModel
|
@@ -81,6 +84,21 @@ def generate_image(request: gr.Request,prompt, negative_prompt, height, width, n
|
|
81 |
generator=torch.Generator(pipe.device).manual_seed(seed)
|
82 |
).images
|
83 |
# testing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
query_data: dict = request.query_params
|
85 |
save_data = {
|
86 |
"prompt": prompt,
|
@@ -91,11 +109,13 @@ def generate_image(request: gr.Request,prompt, negative_prompt, height, width, n
|
|
91 |
"num_images_per_prompt": num_images_per_prompt,
|
92 |
"use_random_seed": use_random_seed,
|
93 |
"seed": seed,
|
94 |
-
"output":
|
95 |
"seed_used" : seed
|
96 |
}
|
|
|
97 |
print(save_data)
|
98 |
print(query_data)
|
|
|
99 |
# url = f"https://bots.spaceship.im/save_data/{query_data['uuid']}"
|
100 |
# res = requests.post(url, json=save_data)
|
101 |
|
|
|
2 |
import os
|
3 |
import torch
|
4 |
import random
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
+
import base64
|
8 |
from huggingface_hub import snapshot_download
|
9 |
from kolors.pipelines.pipeline_stable_diffusion_xl_chatglm_256 import StableDiffusionXLPipeline
|
10 |
from kolors.models.modeling_chatglm import ChatGLMModel
|
|
|
84 |
generator=torch.Generator(pipe.device).manual_seed(seed)
|
85 |
).images
|
86 |
# testing
|
87 |
+
|
88 |
+
|
89 |
+
image = image[0] # Since it's in a list
|
90 |
+
|
91 |
+
# Convert the image to an in-memory byte stream
|
92 |
+
byte_stream = io.BytesIO()
|
93 |
+
image.save(byte_stream, format='PNG') # You can choose other formats like 'JPEG' if needed
|
94 |
+
byte_data = byte_stream.getvalue()
|
95 |
+
|
96 |
+
# Encode the byte stream to a base64 string
|
97 |
+
base64_str = base64.b64encode(byte_data).decode('utf-8')
|
98 |
+
|
99 |
+
# For demonstration, print the base64 string
|
100 |
+
print(base64_str)
|
101 |
+
|
102 |
query_data: dict = request.query_params
|
103 |
save_data = {
|
104 |
"prompt": prompt,
|
|
|
109 |
"num_images_per_prompt": num_images_per_prompt,
|
110 |
"use_random_seed": use_random_seed,
|
111 |
"seed": seed,
|
112 |
+
"output": base64_str,
|
113 |
"seed_used" : seed
|
114 |
}
|
115 |
+
|
116 |
print(save_data)
|
117 |
print(query_data)
|
118 |
+
|
119 |
# url = f"https://bots.spaceship.im/save_data/{query_data['uuid']}"
|
120 |
# res = requests.post(url, json=save_data)
|
121 |
|