PatrickSchrML commited on
Commit
12de648
1 Parent(s): d58bb8d

new endpoint

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -18,6 +18,18 @@ from share_btn import community_icon_html, loading_icon_html, share_js
18
 
19
  is_gpu_busy = False
20
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def infer(prompt, n_samples, steps, scale, seed):
23
  global is_gpu_busy
@@ -41,9 +53,11 @@ def infer(prompt, n_samples, steps, scale, seed):
41
  # images.append(image)
42
  # else:
43
  url = os.getenv('BACKEND_URL')
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.")
49
  else:
 
18
 
19
  is_gpu_busy = False
20
 
21
+ def safe_sd(prompt, n_samples, steps, scale, seed):
22
+ url = os.getenv('BACKEND_URL_NEW')
23
+ res = requests.post(url, json={
24
+ "model": "together/universal-sd",
25
+ "prompt": prompt,
26
+ "n": n_samples,
27
+ "mode": "safe_text2img",
28
+ "steps": steps,
29
+ "seed": seed,
30
+ "guidance_scale": scale,
31
+ })
32
+ return res
33
 
34
  def infer(prompt, n_samples, steps, scale, seed):
35
  global is_gpu_busy
 
53
  # images.append(image)
54
  # else:
55
  url = os.getenv('BACKEND_URL')
56
+ response = safe_sd(prompt, int(n_samples), max(50,int(steps)), f'{scale:.1f}', int(seed))
57
+ #requests.get(url.format(prompt, int(n_samples), max(50,int(steps)), f'{scale:.1f}', int(seed)))
58
  #response = requests.get(url.format('a%20naked%20girl', 2, 50, 7.5, 2))
59
+ #data = json.load(BytesIO(response.content))
60
+ data = response.json()
61
  if 'output' not in data:
62
  raise gr.Error("Although safety guidance is enabled, potential unsafe content found. Please try again with different seed.")
63
  else: