Spaces:
Runtime error
Runtime error
Commit
·
c066480
1
Parent(s):
ca61cfd
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
api_url = "https://codinglehrer.pythonanywhere.com/generate_image"
|
| 5 |
|
|
@@ -14,7 +17,18 @@ def generate_image(prompt, seed=0, negative_prompt="", model="Deliberate", sampl
|
|
| 14 |
}
|
| 15 |
response = requests.post(api_url, data=data)
|
| 16 |
if response.status_code == 200:
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
else:
|
| 19 |
return None
|
| 20 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
import os
|
| 4 |
+
import base64
|
| 5 |
+
|
| 6 |
|
| 7 |
api_url = "https://codinglehrer.pythonanywhere.com/generate_image"
|
| 8 |
|
|
|
|
| 17 |
}
|
| 18 |
response = requests.post(api_url, data=data)
|
| 19 |
if response.status_code == 200:
|
| 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 |
|