John6666 commited on
Commit
ebae902
·
verified ·
1 Parent(s): f83a980

Update models.py

Browse files

https://cookbook.openai.com/examples/generate_images_with_gpt_image

Files changed (1) hide show
  1. models.py +5 -11
models.py CHANGED
@@ -156,18 +156,12 @@ def generate_remixed_image(
156
  model="gpt-image-1",
157
  prompt=final_prompt,
158
  size="1024x1024",
159
- quality="medium", # valid: low | medium | high | auto
160
- response_format="url", # return URLs, so the next lines keep working
161
- n=1
162
  )
163
-
164
- # Get the URL and download the image
165
- image_url = dalle_response.data[0].url
166
-
167
- image_data = requests.get(image_url).content
168
-
169
- remixed_image = Image.open(BytesIO(image_data))
170
-
171
  return final_prompt, remixed_image
172
 
173
  except Exception as e:
 
156
  model="gpt-image-1",
157
  prompt=final_prompt,
158
  size="1024x1024",
159
+ quality="medium", # valid: low | medium | high | auto
160
+ n=1,
 
161
  )
162
+ b64 = dalle_response.data[0].b64_json
163
+ img_bytes = base64.b64decode(b64)
164
+ remixed_image = Image.open(BytesIO(img_bytes)).convert("RGB")
 
 
 
 
 
165
  return final_prompt, remixed_image
166
 
167
  except Exception as e: