Walmart-the-bag commited on
Commit
ae12cbe
·
verified ·
1 Parent(s): 65fe587

Full Fix: All issues, image response fix, file fix, webp fix

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -15,26 +15,26 @@ def generate_image(prompt, model):
15
  }
16
  try:
17
  response = requests.post(url, headers=headers, data=json.dumps(data))
 
18
  if response.status_code == 200:
19
  response_data = response.json()
20
  image_id = response_data.get("id")
 
21
  if not image_id:
22
  return "Error: No image ID returned in the response."
23
 
24
  while True:
25
  status_response = requests.get(f"{url}/{image_id}")
 
26
  if status_response.status_code == 200:
27
  status_data = status_response.json()
28
  status = status_data.get("status")
 
29
  if status == "completed":
30
  images = status_data.get("images")
31
  if images and isinstance(images, list):
32
- image_data = images[0]
33
- if image_data.startswith("data:image"):
34
- base64_data = image_data.split(",", 1)[1]
35
- return base64_data
36
- else:
37
- return "Error: Unexpected image data format."
38
  else:
39
  return "Error: No images found in the response."
40
  elif status == "error":
@@ -60,8 +60,8 @@ iface = gr.Interface(
60
  gr.Textbox(label="Enter prompt"),
61
  gr.Radio(["dalle2"], label="Select Model")
62
  ],
63
- outputs=gr.Image(type="pil"),
64
  title="DALLE2 Generation",
65
- description="Disclaimer: This uses the Nexra API for image generation. I cannot guarantee rate limits, if you do not recieve an image please try again. I will change to use a different API soon. DALL-E 3 is not supported yet."
66
  )
67
  iface.launch()
 
15
  }
16
  try:
17
  response = requests.post(url, headers=headers, data=json.dumps(data))
18
+
19
  if response.status_code == 200:
20
  response_data = response.json()
21
  image_id = response_data.get("id")
22
+
23
  if not image_id:
24
  return "Error: No image ID returned in the response."
25
 
26
  while True:
27
  status_response = requests.get(f"{url}/{image_id}")
28
+
29
  if status_response.status_code == 200:
30
  status_data = status_response.json()
31
  status = status_data.get("status")
32
+
33
  if status == "completed":
34
  images = status_data.get("images")
35
  if images and isinstance(images, list):
36
+ image_url = images[0]
37
+ return image_url
 
 
 
 
38
  else:
39
  return "Error: No images found in the response."
40
  elif status == "error":
 
60
  gr.Textbox(label="Enter prompt"),
61
  gr.Radio(["dalle2"], label="Select Model")
62
  ],
63
+ outputs=gr.Image(type="filepath"),
64
  title="DALLE2 Generation",
65
+ description="DALLE-2 Generation from Nextra API, NOTE: DALL-E 3 is not supported yet."
66
  )
67
  iface.launch()