Spaces:
Running
Running
Update app_with_diffusers.py
Browse files- app_with_diffusers.py +36 -4
app_with_diffusers.py
CHANGED
@@ -39,14 +39,42 @@ pipe.aggregator.load_state_dict(pretrained_state_dict)
|
|
39 |
pipe.to(device='cuda', dtype=torch.float16)
|
40 |
pipe.aggregator.to(device='cuda', dtype=torch.float16)
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
# load a broken image
|
44 |
low_quality_image = Image.open(input_image).convert("RGB")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# InstantIR restoration
|
47 |
image = pipe(
|
48 |
-
prompt=prompt,
|
49 |
-
image=
|
|
|
|
|
|
|
|
|
|
|
50 |
previewer_scheduler=lcm_scheduler,
|
51 |
).images[0]
|
52 |
|
@@ -54,12 +82,16 @@ def infer(prompt, input_image):
|
|
54 |
|
55 |
import gradio as gr
|
56 |
|
|
|
|
|
57 |
with gr.Blocks() as demo:
|
58 |
with gr.Column():
|
59 |
with gr.Row():
|
60 |
with gr.Column():
|
61 |
lq_img = gr.Image(label="Low-quality image", type="filepath")
|
62 |
-
|
|
|
|
|
63 |
submit_btn = gr.Button("InstantIR magic!")
|
64 |
output_img = gr.Image(label="InstantIR restored")
|
65 |
submit_btn.click(
|
|
|
39 |
pipe.to(device='cuda', dtype=torch.float16)
|
40 |
pipe.aggregator.to(device='cuda', dtype=torch.float16)
|
41 |
|
42 |
+
PROMPT = "Photorealistic, highly detailed, hyper detailed photo - realistic maximum detail, 32k, \
|
43 |
+
ultra HD, extreme meticulous detailing, skin pore detailing, \
|
44 |
+
hyper sharpness, perfect without deformations, \
|
45 |
+
taken using a Canon EOS R camera, Cinematic, High Contrast, Color Grading. "
|
46 |
+
|
47 |
+
NEG_PROMPT = "blurry, out of focus, unclear, depth of field, over-smooth, \
|
48 |
+
sketch, oil painting, cartoon, CG Style, 3D render, unreal engine, \
|
49 |
+
dirty, messy, worst quality, low quality, frames, painting, illustration, drawing, art, \
|
50 |
+
watermark, signature, jpeg artifacts, deformed, lowres"
|
51 |
+
|
52 |
+
def infer(prompt, input_image, steps=30, cfg_scale=7.0, guidance_end=1.0,
|
53 |
+
creative_restoration=False, seed=3407, height=1024, width=1024):
|
54 |
+
|
55 |
+
|
56 |
# load a broken image
|
57 |
low_quality_image = Image.open(input_image).convert("RGB")
|
58 |
+
|
59 |
+
lq = [resize_img(low_quality_image, size=(width, height))]
|
60 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
61 |
+
timesteps = [
|
62 |
+
i * (1000//steps) + pipe.scheduler.config.steps_offset for i in range(0, steps)
|
63 |
+
]
|
64 |
+
timesteps = timesteps[::-1]
|
65 |
+
|
66 |
+
prompt = PROMPT if len(prompt)==0 else prompt
|
67 |
+
neg_prompt = NEG_PROMPT
|
68 |
|
69 |
# InstantIR restoration
|
70 |
image = pipe(
|
71 |
+
prompt=[prompt]*len(lq),
|
72 |
+
image=lq,
|
73 |
+
num_inference_steps=steps,
|
74 |
+
generator=generator,
|
75 |
+
timesteps=timesteps,
|
76 |
+
negative_prompt=[neg_prompt]*len(lq),
|
77 |
+
guidance_scale=cfg_scale,
|
78 |
previewer_scheduler=lcm_scheduler,
|
79 |
).images[0]
|
80 |
|
|
|
82 |
|
83 |
import gradio as gr
|
84 |
|
85 |
+
|
86 |
+
|
87 |
with gr.Blocks() as demo:
|
88 |
with gr.Column():
|
89 |
with gr.Row():
|
90 |
with gr.Column():
|
91 |
lq_img = gr.Image(label="Low-quality image", type="filepath")
|
92 |
+
with gr.Group():
|
93 |
+
prompt = gr.Textbox(label="Prompt", value="")
|
94 |
+
|
95 |
submit_btn = gr.Button("InstantIR magic!")
|
96 |
output_img = gr.Image(label="InstantIR restored")
|
97 |
submit_btn.click(
|