Spaces:
Runtime error
Runtime error
Commit
·
199ccb7
1
Parent(s):
3d0d32e
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://5cb20b40-572c-426f-9466-995256f9b6eb.id.repl.co/generate_image"
|
| 5 |
|
|
@@ -7,7 +10,10 @@ def generate_image(prompt, seed=0, negative_prompt="", model="Deliberate", sampl
|
|
| 7 |
data = "?prompt="+ prompt + "&seed="+ str(seed) + "&negative_prompt=" + negative_prompt + "&model=" + model + "&sampler=" + sampler + "&steps=" + str(steps)
|
| 8 |
response = requests.post(api_url, data=data)
|
| 9 |
if response.status_code == 200:
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
else:
|
| 12 |
return None
|
| 13 |
|
|
@@ -28,4 +34,4 @@ interface = gr.Interface(generate_image, inputs, outputs, title="<a href='https:
|
|
| 28 |
["A landscape with mountains and a lake"],
|
| 29 |
["A portrait of a woman with red hair"]])
|
| 30 |
|
| 31 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
import base64
|
| 6 |
|
| 7 |
api_url = "https://5cb20b40-572c-426f-9466-995256f9b6eb.id.repl.co/generate_image"
|
| 8 |
|
|
|
|
| 10 |
data = "?prompt="+ prompt + "&seed="+ str(seed) + "&negative_prompt=" + negative_prompt + "&model=" + model + "&sampler=" + sampler + "&steps=" + str(steps)
|
| 11 |
response = requests.post(api_url, data=data)
|
| 12 |
if response.status_code == 200:
|
| 13 |
+
img_base64 = response.json()["url"]
|
| 14 |
+
img_bytes = base64.b64decode(img_base64)
|
| 15 |
+
img = Image.open(BytesIO(img_bytes))
|
| 16 |
+
return img
|
| 17 |
else:
|
| 18 |
return None
|
| 19 |
|
|
|
|
| 34 |
["A landscape with mountains and a lake"],
|
| 35 |
["A portrait of a woman with red hair"]])
|
| 36 |
|
| 37 |
+
interface.launch()
|