Spaces:
Runtime error
Runtime error
Commit ·
895d93f
1
Parent(s): 63a6e70
Pure external backend (#804)
Browse files- Pure external backend (b7a47493cada27eb0e5727eff02d877dad5684c8)
16 unmodified lines17181920212223242511 unmodified lines373839404142434445464748495051525354555657585960616263646566305 unmodified lines37237337437516 unmodified linesdevice = "cuda"#If you are running this code locally, you need to either do a 'huggingface-cli login` or paste your User Access Token from here https://huggingface.co/settings/tokens into the use_auth_token field below.pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True, revision="fp16", torch_dtype=torch.float16)pipe = pipe.to(device)torch.backends.cudnn.benchmark = True#When running locally, you won`t have access to this, so you can remove this partword_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)11 unmodified linesraise gr.Error("Unsafe content found. Please try again with different prompts.")#generator = torch.Generator(device=device).manual_seed(seed)print("Is GPU busy? ", is_gpu_busy)images = []if(not is_gpu_busy):is_gpu_busy = Trueimages_list = pipe([prompt] * samples,num_inference_steps=steps,guidance_scale=scale,#generator=generator,)is_gpu_busy = Falsesafe_image = Image.open(r"unsafe.png")for i, image in enumerate(images_list["sample"]):if(images_list["nsfw_content_detected"][i]):images.append(safe_image)else:images.append(image)else:url = os.getenv('JAX_BACKEND_URL')payload = {'prompt': prompt}images_request = requests.post(url, json = payload)for image in images_request.json()["images"]:image_decoded = Image.open(BytesIO(base64.b64decode(image)))images.append(image_decoded)return images, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)305 unmodified lines""")block.queue(max_size=25, concurrency_count=2).launch()16 unmodified lines17181920212223242511 unmodified lines373839404142434445464748495051525354555657585960616263646566305 unmodified lines37237337437516 unmodified linesdevice = "cuda"#If you are running this code locally, you need to either do a 'huggingface-cli login` or paste your User Access Token from here https://huggingface.co/settings/tokens into the use_auth_token field below.#pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True, revision="fp16", torch_dtype=torch.float16)#pipe = pipe.to(device)#torch.backends.cudnn.benchmark = True#When running locally, you won`t have access to this, so you can remove this partword_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt", use_auth_token=True)11 unmodified linesraise gr.Error("Unsafe content found. Please try again with different prompts.")#generator = torch.Generator(device=device).manual_seed(seed)#print("Is GPU busy? ", is_gpu_busy)images = []#if(not is_gpu_busy):# is_gpu_busy = True# images_list = pipe(# [prompt] * samples,# num_inference_steps=steps,# guidance_scale=scale,#generator=generator,# )# is_gpu_busy = False# safe_image = Image.open(r"unsafe.png")# for i, image in enumerate(images_list["sample"]):# if(images_list["nsfw_content_detected"][i]):# images.append(safe_image)# else:# images.append(image)#else:url = os.getenv('JAX_BACKEND_URL')payload = {'prompt': prompt}images_request = requests.post(url, json = payload)for image in images_request.json()["images"]:image_decoded = Image.open(BytesIO(base64.b64decode(image)))images.append(image_decoded)return images, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)305 unmodified lines""")block.queue(max_size=50, concurrency_count=40).launch()
app.py+26-26