Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Use custom demo instead of GKE
Browse filesRequires a secret update.
This reverts commit f076b93a6b1c70c786b09972234d67ac160517cd.
app.py
CHANGED
|
@@ -5,7 +5,6 @@ from datasets import load_dataset
|
|
| 5 |
import base64
|
| 6 |
import re
|
| 7 |
import os
|
| 8 |
-
import random
|
| 9 |
import requests
|
| 10 |
import time
|
| 11 |
from PIL import Image
|
|
@@ -89,11 +88,10 @@ def infer(prompt, negative="low_quality", scale=7, style_name=None, profile: gr.
|
|
| 89 |
if re.search(rf"\b{filter}\b", prompt):
|
| 90 |
raise gr.Error("Please try again with a different prompt")
|
| 91 |
|
| 92 |
-
seed = random.randint(0,4294967295)
|
| 93 |
prompt, negative = apply_style(style_name, prompt, negative)
|
| 94 |
images = []
|
| 95 |
url = os.getenv('JAX_BACKEND_URL')
|
| 96 |
-
payload = {'
|
| 97 |
start_time = time.time()
|
| 98 |
images_request = requests.post(url, json = payload)
|
| 99 |
print(time.time() - start_time)
|
|
@@ -102,23 +100,22 @@ def infer(prompt, negative="low_quality", scale=7, style_name=None, profile: gr.
|
|
| 102 |
except requests.exceptions.JSONDecodeError:
|
| 103 |
raise gr.Error("SDXL did not return a valid result, try again")
|
| 104 |
|
| 105 |
-
for
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
images.append(image_b64)
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
|
| 123 |
return images, gr.update(visible=True)
|
| 124 |
|
|
|
|
| 5 |
import base64
|
| 6 |
import re
|
| 7 |
import os
|
|
|
|
| 8 |
import requests
|
| 9 |
import time
|
| 10 |
from PIL import Image
|
|
|
|
| 88 |
if re.search(rf"\b{filter}\b", prompt):
|
| 89 |
raise gr.Error("Please try again with a different prompt")
|
| 90 |
|
|
|
|
| 91 |
prompt, negative = apply_style(style_name, prompt, negative)
|
| 92 |
images = []
|
| 93 |
url = os.getenv('JAX_BACKEND_URL')
|
| 94 |
+
payload = {'prompt': prompt, 'negative_prompt': negative, 'guidance_scale': scale}
|
| 95 |
start_time = time.time()
|
| 96 |
images_request = requests.post(url, json = payload)
|
| 97 |
print(time.time() - start_time)
|
|
|
|
| 100 |
except requests.exceptions.JSONDecodeError:
|
| 101 |
raise gr.Error("SDXL did not return a valid result, try again")
|
| 102 |
|
| 103 |
+
for image in json_data["images"]:
|
| 104 |
+
image_b64 = (f"data:image/jpeg;base64,{image}")
|
| 105 |
+
images.append(image_b64)
|
|
|
|
| 106 |
|
| 107 |
+
if profile is not None: # avoid conversion on non-logged-in users
|
| 108 |
+
pil_image = Image.open(BytesIO(base64.b64decode(image)))
|
| 109 |
+
user_history.save_image( # save images + metadata to user history
|
| 110 |
+
label=prompt,
|
| 111 |
+
image=pil_image,
|
| 112 |
+
profile=profile,
|
| 113 |
+
metadata={
|
| 114 |
+
"prompt": prompt,
|
| 115 |
+
"negative_prompt": negative,
|
| 116 |
+
"guidance_scale": scale,
|
| 117 |
+
},
|
| 118 |
+
)
|
| 119 |
|
| 120 |
return images, gr.update(visible=True)
|
| 121 |
|