ImagineAI-Real commited on
Commit
b84f132
1 Parent(s): a8f27e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import requests
3
  import os
4
  import base64
 
5
 
6
 
7
  api_url = "https://codinglehrer.pythonanywhere.com/generate_image"
@@ -20,15 +21,11 @@ def generate_image(prompt, seed=0, negative_prompt="", model="Deliberate", sampl
20
  # Decode the base64 image string
21
  img_bytes = base64.b64decode(response.json()["url"])
22
 
23
- # Save the image in the images folder
24
- if not os.path.exists("images"):
25
- os.makedirs("images")
26
- filename = f"images/{seed}.png"
27
- with open(filename, 'wb') as f:
28
- f.write(img_bytes)
29
 
30
- # Return the path of the saved image file
31
- return filename
32
  else:
33
  return None
34
 
 
2
  import requests
3
  import os
4
  import base64
5
+ from PIL import Image
6
 
7
 
8
  api_url = "https://codinglehrer.pythonanywhere.com/generate_image"
 
21
  # Decode the base64 image string
22
  img_bytes = base64.b64decode(response.json()["url"])
23
 
24
+ # Open the image using Pillow
25
+ img = Image.open(io.BytesIO(img_bytes))
 
 
 
 
26
 
27
+ # Return the image object
28
+ return img
29
  else:
30
  return None
31