Spaces:
Build error
Build error
PatrickSchrML
commited on
Commit
·
e3dc2e8
1
Parent(s):
a27d199
default and safe
Browse files
app.py
CHANGED
@@ -50,26 +50,13 @@ def infer(prompt, n_samples, steps, scale, seed):
|
|
50 |
im = Image.open(BytesIO(base64.b64decode(image['image_base64'])))
|
51 |
images.append(im)
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
"prompt": prompt,
|
56 |
-
"n": int(n_samples),
|
57 |
-
"height": 512,
|
58 |
-
"width": 512,
|
59 |
-
"steps": max(50, int(steps)),
|
60 |
-
"seed": int(seed),
|
61 |
-
"guidance_scale": scale,
|
62 |
-
}, headers={
|
63 |
-
"User-Agent": "YOUR_NAME_HERE"
|
64 |
-
})
|
65 |
|
66 |
data = json.load(BytesIO(response.content))
|
67 |
if 'output' not in data:
|
68 |
-
raise gr.Error(
|
69 |
-
"Although safety guidance is enabled, potential unsafe content found. Please try again with different seed.")
|
70 |
else:
|
71 |
-
if data['output']['result_type'] == "error":
|
72 |
-
raise gr.Error(data['output']['value'])
|
73 |
for image in data['output']['choices']:
|
74 |
im = Image.open(BytesIO(base64.b64decode(image['image_base64'])))
|
75 |
images.append(im)
|
|
|
50 |
im = Image.open(BytesIO(base64.b64decode(image['image_base64'])))
|
51 |
images.append(im)
|
52 |
|
53 |
+
url = os.getenv('BACKEND_URL_SAFE')
|
54 |
+
response = requests.get(url.format(prompt, int(n_samples), max(50, int(steps)), f'{scale:.1f}', int(seed)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
data = json.load(BytesIO(response.content))
|
57 |
if 'output' not in data:
|
58 |
+
raise gr.Error("An error occurred.")
|
|
|
59 |
else:
|
|
|
|
|
60 |
for image in data['output']['choices']:
|
61 |
im = Image.open(BytesIO(base64.b64decode(image['image_base64'])))
|
62 |
images.append(im)
|