Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,6 +49,11 @@ pipe_edit = StableDiffusionXLInstructPix2PixPipeline.from_single_file( edit_file
|
|
| 49 |
pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")
|
| 50 |
pipe_edit.to("cuda")
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# Generator
|
| 53 |
@spaces.GPU(duration=30, queue=False)
|
| 54 |
def king(type ,
|
|
@@ -66,6 +71,11 @@ def king(type ,
|
|
| 66 |
progress=gr.Progress(track_tqdm=True),
|
| 67 |
):
|
| 68 |
if type=="Image Editing" :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
if randomize_seed:
|
| 70 |
seed = random.randint(0, 99999)
|
| 71 |
text_cfg_scale = text_cfg_scale
|
|
@@ -74,13 +84,13 @@ def king(type ,
|
|
| 74 |
steps=steps
|
| 75 |
generator = torch.manual_seed(seed)
|
| 76 |
output_image = pipe_edit(
|
| 77 |
-
|
| 78 |
guidance_scale=text_cfg_scale, image_guidance_scale=image_cfg_scale,
|
| 79 |
num_inference_steps=steps, generator=generator, output_type="latent",
|
| 80 |
).images
|
| 81 |
|
| 82 |
refine = refiner(
|
| 83 |
-
prompt=
|
| 84 |
guidance_scale=guidance_scale,
|
| 85 |
num_inference_steps=steps,
|
| 86 |
image=output_image,
|
|
|
|
| 49 |
pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")
|
| 50 |
pipe_edit.to("cuda")
|
| 51 |
|
| 52 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
| 53 |
+
|
| 54 |
+
processor = BlipProcessor.from_pretrained("unography/blip-long-cap")
|
| 55 |
+
model = BlipForConditionalGeneration.from_pretrained("unography/blip-long-cap", torch_dtype=torch.float16).to("cuda")
|
| 56 |
+
|
| 57 |
# Generator
|
| 58 |
@spaces.GPU(duration=30, queue=False)
|
| 59 |
def king(type ,
|
|
|
|
| 71 |
progress=gr.Progress(track_tqdm=True),
|
| 72 |
):
|
| 73 |
if type=="Image Editing" :
|
| 74 |
+
raw_image = Image.open(input_image).convert('RGB')
|
| 75 |
+
inputs = processor(raw_image, return_tensors="pt").to("cuda", torch.float16)
|
| 76 |
+
out = model.generate(**inputs, min_length=10, max_length=25)
|
| 77 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
| 78 |
+
instructions = f"{instruction} {caption} {instruction}"
|
| 79 |
if randomize_seed:
|
| 80 |
seed = random.randint(0, 99999)
|
| 81 |
text_cfg_scale = text_cfg_scale
|
|
|
|
| 84 |
steps=steps
|
| 85 |
generator = torch.manual_seed(seed)
|
| 86 |
output_image = pipe_edit(
|
| 87 |
+
instructions, image=input_image,
|
| 88 |
guidance_scale=text_cfg_scale, image_guidance_scale=image_cfg_scale,
|
| 89 |
num_inference_steps=steps, generator=generator, output_type="latent",
|
| 90 |
).images
|
| 91 |
|
| 92 |
refine = refiner(
|
| 93 |
+
prompt=instruction2,
|
| 94 |
guidance_scale=guidance_scale,
|
| 95 |
num_inference_steps=steps,
|
| 96 |
image=output_image,
|