Update app.py
Browse files
app.py
CHANGED
@@ -5,11 +5,9 @@ import json
|
|
5 |
import time
|
6 |
import os
|
7 |
import re
|
8 |
-
import base64
|
9 |
-
from io import BytesIO
|
10 |
-
from PIL import Image
|
11 |
|
12 |
_COOKIES = os.environ.get("COOKIES", "")
|
|
|
13 |
|
14 |
API_KEY = os.getenv("API_KEY", "linux.do")
|
15 |
|
@@ -194,23 +192,6 @@ def chat_completions():
|
|
194 |
# 检查响应状态码是否为200
|
195 |
if _data[0]["status"] == "completed":
|
196 |
print("图片生成完成:", job_id)
|
197 |
-
# 分离出 header 和 base64 编码的数据
|
198 |
-
_header, _encoded = _data[0]["result"].split(',', 1)
|
199 |
-
# 解码 base64 得到二进制数据
|
200 |
-
webp_data = base64.b64decode(_encoded)
|
201 |
-
|
202 |
-
# 使用 BytesIO 将二进制数据转换为 PIL Image 对象
|
203 |
-
input_buffer = BytesIO(webp_data)
|
204 |
-
_image = Image.open(input_buffer)
|
205 |
-
|
206 |
-
# 创建一个 BytesIO 缓存用于存储 PNG 数据
|
207 |
-
output_buffer = BytesIO()
|
208 |
-
_image.save(output_buffer, format="PNG")
|
209 |
-
png_data = output_buffer.getvalue()
|
210 |
-
|
211 |
-
# 将 PNG 二进制数据转换为 base64 编码
|
212 |
-
encoded_png = base64.b64encode(png_data).decode('utf-8')
|
213 |
-
data_png = "data:image/png;base64," + encoded_png
|
214 |
return Response(
|
215 |
json.dumps({
|
216 |
"object": "chat.completion",
|
@@ -221,7 +202,7 @@ def chat_completions():
|
|
221 |
"index": 0,
|
222 |
"message": {
|
223 |
"role": "user",
|
224 |
-
"content":
|
225 |
},
|
226 |
"finish_reason": "stop"
|
227 |
}
|
|
|
5 |
import time
|
6 |
import os
|
7 |
import re
|
|
|
|
|
|
|
8 |
|
9 |
_COOKIES = os.environ.get("COOKIES", "")
|
10 |
+
_COOKIES = "session_token=955b54566c702e02d011fd41b6d913c3b136dc6c3d67ba6d6ef89b6fac4086eb; cf_clearance=e0TWZDlzBpV28hqeENTPBMjX9rgxAtZBsrK3_vpisDA-1740845308-1.2.1.1-R4D99qqFa0Y2um46_2sWjttiyVEPDPM2MrpoL2xwzdwEsDFVCXsynY3AyOrO4bmtCIyebHsS_05JXsv_YqAdFpSdneBNdgnW0zkgGsP1HZiBv.Gdb_vE8LsGpNz19FynpCdOfcOXB0J3lnx4epF.BWaykyT140O38VPYKGUhr0H9BnOVg7KAI727twEqhCC8DMMgn81qV8Vp1YaDmDX_EBzA76eKU5CwjxxVDZrxzaGZDbkCyho.OsUeqIBFWELI.5G0K42MNrMVEy0S0pEFfWIzbkVXAFj_mvFUgyITnC9aaMna9HI0VnBT1dJ4G__gLrNS.CpGneS5QicBAvn58su7raHd9i4_uOuBWgkldZpCD2Dp_b2v0EYtOKFH1Lji1oNL6IgyLzE_Y4ghOgcELWFcLERQKgutGfCA6PaYze8"
|
11 |
|
12 |
API_KEY = os.getenv("API_KEY", "linux.do")
|
13 |
|
|
|
192 |
# 检查响应状态码是否为200
|
193 |
if _data[0]["status"] == "completed":
|
194 |
print("图片生成完成:", job_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
return Response(
|
196 |
json.dumps({
|
197 |
"object": "chat.completion",
|
|
|
202 |
"index": 0,
|
203 |
"message": {
|
204 |
"role": "user",
|
205 |
+
"content": _data[0]["result"]
|
206 |
},
|
207 |
"finish_reason": "stop"
|
208 |
}
|