|  | @@ -15,18 +15,28 @@ import base64
 | 
	
		
			
				|  |  |  server_address = "127.0.0.1:8188"
 | 
	
		
			
				|  |  |  client_id = str(uuid.uuid4())
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def load_debug_ai_scene_info():
 | 
	
		
			
				|  |  | +    #open ai_scene_info.json
 | 
	
		
			
				|  |  | +    with open("D:/Git/ap-canvas-creation-module/04_stable_diffusion/ai_scene_info.json", "r") as f:
 | 
	
		
			
				|  |  | +        ai_scene_info = json.load(f)
 | 
	
		
			
				|  |  | +    return ai_scene_info
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  def convert_base64_string_to_object(base64_string):
 | 
	
		
			
				|  |  |      bytes = base64.b64decode(base64_string)
 | 
	
		
			
				|  |  |      string = bytes.decode("ascii")
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      return json.loads(string)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  def set_filename(json_obj, title, new_prefix):
 | 
	
		
			
				|  |  |      for key, value in json_obj.items():
 | 
	
		
			
				|  |  |          if isinstance(value, dict):
 | 
	
		
			
				|  |  |              if value.get("_meta", {}).get("title") == title:
 | 
	
		
			
				|  |  |                  if "inputs" in value and "filename_prefix" in value["inputs"]:
 | 
	
		
			
				|  |  |                      value["inputs"]["filename_prefix"] = new_prefix
 | 
	
		
			
				|  |  | +                    return new_prefix
 | 
	
		
			
				|  |  |                  else:
 | 
	
		
			
				|  |  |                      result = set_filename(value, title, new_prefix)
 | 
	
		
			
				|  |  |                      if result:
 | 
	
	
		
			
				|  | @@ -45,6 +55,7 @@ def find_node(json_obj, title):
 | 
	
		
			
				|  |  |      return None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  def queue_prompt(prompt):
 | 
	
		
			
				|  |  |      p = {"prompt": prompt, "client_id": client_id}
 | 
	
		
			
				|  |  |      data = json.dumps(p).encode('utf-8')
 | 
	
	
		
			
				|  | @@ -70,7 +81,8 @@ def get_prompt(ai_scene_info):
 | 
	
		
			
				|  |  |      # image_depth_path = image_path + "depth0001.png"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      prompt = json.loads(prompt_text_json)
 | 
	
		
			
				|  |  | -    set_filename(prompt, "Save Image", "{project_id}/basic_api_example".format(project_id=ai_scene_info["project_id"]))
 | 
	
		
			
				|  |  | +    file_name =  set_filename(prompt, "Save Image", "{project_id}/basic_api_example".format(project_id=ai_scene_info["project_id"]))
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      ksampler_main = find_node(prompt, "KSampler")
 | 
	
		
			
				|  |  |      ksampler_main["inputs"]["noise_seed"] = random.randint(0, 1000000)
 | 
	
	
		
			
				|  | @@ -150,12 +162,20 @@ def main():
 | 
	
		
			
				|  |  |      except Exception as e:
 | 
	
		
			
				|  |  |          print("Error:", e)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    ai_scene_info = load_debug_ai_scene_info()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      prompt = get_prompt(ai_scene_info)    
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      ws = websocket.WebSocket()
 | 
	
		
			
				|  |  |      ws.connect("ws://{}/ws?clientId={}".format(server_address, client_id))
 | 
	
		
			
				|  |  |      images = get_images(ws, prompt)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    prompt_id = queue_prompt(prompt)['prompt_id']
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      #Commented out code to display the output images:
 |