warhawkmonk commited on
Commit
cdfcd1a
·
verified ·
1 Parent(s): a19bc4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -298,8 +298,43 @@ def numpy_to_list(array):
298
  # pipe=load_model()
299
  # image = pipe(prompt).images[0]
300
  # return image
 
 
301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  def model_out_put(init_image,mask_image,prompt,negative_prompt):
 
 
 
 
303
  API_URL = "https://8417-201-238-124-65.ngrok-free.app/api/llm-response"
304
  initial_image_base64 = numpy_to_list(np.array(init_image))
305
  mask_image_base64 = numpy_to_list(np.array(mask_image))
 
298
  # pipe=load_model()
299
  # image = pipe(prompt).images[0]
300
  # return image
301
+ def refer_api(prompt):
302
+ invoke_url = "https://ai.api.nvidia.com/v1/genai/stabilityai/stable-diffusion-3-medium"
303
 
304
+ headers = {
305
+ "Authorization": "Bearer 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",
306
+ "Accept": "application/json",
307
+ }
308
+
309
+ payload = {
310
+ "prompt": prompt,
311
+ "cfg_scale": 5,
312
+ "aspect_ratio": "16:9",
313
+ "seed": 0,
314
+ "steps": 50,
315
+ "negative_prompt": ""
316
+ }
317
+
318
+
319
+ response = requests.post(invoke_url, headers=headers, json=payload)
320
+
321
+ response.raise_for_status()
322
+ response_body = response.json()
323
+ def string_to_image(base64_string):
324
+ if ',' in base64_string:
325
+ base64_string = base64_string.split(',')[1]
326
+ # Decode base64 string to bytes
327
+ image_data = base64.b64decode(base64_string)
328
+ # Open image from bytes
329
+ image = Image.open(BytesIO(image_data))
330
+ return image
331
+ return string_to_image(response_body['image'])
332
+
333
  def model_out_put(init_image,mask_image,prompt,negative_prompt):
334
+ if all(mask_image):
335
+ l,m=init_image.shape
336
+ image =refer_api(prompt).resize((l,m))
337
+ return image
338
  API_URL = "https://8417-201-238-124-65.ngrok-free.app/api/llm-response"
339
  initial_image_base64 = numpy_to_list(np.array(init_image))
340
  mask_image_base64 = numpy_to_list(np.array(mask_image))