Update app.py
Browse files
app.py
CHANGED
@@ -1097,20 +1097,27 @@ def handsome_images_generations():
|
|
1097 |
try:
|
1098 |
images = response_json.get("images", [])
|
1099 |
openai_images = []
|
1100 |
-
for
|
1101 |
-
if
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
|
|
|
|
|
|
|
|
|
|
1112 |
else:
|
1113 |
-
|
|
|
|
|
1114 |
|
1115 |
response_data = {
|
1116 |
"created": int(time.time()),
|
|
|
1097 |
try:
|
1098 |
images = response_json.get("images", [])
|
1099 |
openai_images = []
|
1100 |
+
for item in images:
|
1101 |
+
if isinstance(item, dict) and "url" in item:
|
1102 |
+
image_url = item["url"]
|
1103 |
+
print(f"image_url: {image_url}") # 打印 URL
|
1104 |
+
if data.get("response_format") == "b64_json":
|
1105 |
+
try:
|
1106 |
+
image_data = requests.get(image_url, stream=True).raw
|
1107 |
+
image = Image.open(image_data)
|
1108 |
+
buffered = io.BytesIO()
|
1109 |
+
image.save(buffered, format="PNG")
|
1110 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
1111 |
+
openai_images.append({"b64_json": img_str})
|
1112 |
+
except Exception as e:
|
1113 |
+
logging.error(f"图片转base64失败: {e}")
|
1114 |
+
openai_images.append({"url": image_url})
|
1115 |
+
else:
|
1116 |
+
openai_images.append({"url": image_url})
|
1117 |
else:
|
1118 |
+
logging.error(f"无效的图片数据: {item}")
|
1119 |
+
openai_images.append({"url": item})
|
1120 |
+
|
1121 |
|
1122 |
response_data = {
|
1123 |
"created": int(time.time()),
|