PatrickSchrML commited on
Commit
7013f52
1 Parent(s): 412b339

default and safe

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -24,7 +24,6 @@ def infer(prompt, n_samples, steps, scale, seed):
24
  # generator = torch.Generator(device=device).manual_seed(seed)
25
  # print("Is GPU busy? ", is_gpu_busy)
26
  images = []
27
- images_default = []
28
 
29
  url = os.getenv('BACKEND_URL_DEFAULT')
30
 
@@ -41,8 +40,6 @@ def infer(prompt, n_samples, steps, scale, seed):
41
  "User-Agent": "YOUR_NAME_HERE"
42
  })
43
 
44
- #response = requests.get(url.format(prompt, int(n_samples), max(50,int(steps)), f'{scale:.1f}', int(seed)))
45
- #response = requests.get(url.format('a%20naked%20girl', 2, 50, 7.5, 2))
46
  data = json.load(BytesIO(response.content))
47
  if 'output' not in data:
48
  raise gr.Error("Although safety guidance is enabled, potential unsafe content found. Please try again with different seed.")
@@ -53,6 +50,29 @@ def infer(prompt, n_samples, steps, scale, seed):
53
  im = Image.open(BytesIO(base64.b64decode(image['image_base64'])))
54
  images.append(im)
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  return images
57
 
58
 
@@ -260,7 +280,7 @@ with block:
260
 
261
  gallery = gr.Gallery(
262
  label="Generated images", show_label=False, elem_id="gallery"
263
- ).style(grid=[1], height="auto")
264
 
265
  with gr.Group(elem_id="container-advanced-btns"):
266
  advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
 
24
  # generator = torch.Generator(device=device).manual_seed(seed)
25
  # print("Is GPU busy? ", is_gpu_busy)
26
  images = []
 
27
 
28
  url = os.getenv('BACKEND_URL_DEFAULT')
29
 
 
40
  "User-Agent": "YOUR_NAME_HERE"
41
  })
42
 
 
 
43
  data = json.load(BytesIO(response.content))
44
  if 'output' not in data:
45
  raise gr.Error("Although safety guidance is enabled, potential unsafe content found. Please try again with different seed.")
 
50
  im = Image.open(BytesIO(base64.b64decode(image['image_base64'])))
51
  images.append(im)
52
 
53
+ response = requests.post(url, json={
54
+ "model": "SafeStableDiffusion",
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)
76
  return images
77
 
78
 
 
280
 
281
  gallery = gr.Gallery(
282
  label="Generated images", show_label=False, elem_id="gallery"
283
+ ).style(grid=[2], height="auto")
284
 
285
  with gr.Group(elem_id="container-advanced-btns"):
286
  advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")