Spaces:
Runtime error
Runtime error
baseline
Browse files
app.py
CHANGED
@@ -5,14 +5,14 @@ import hashlib
|
|
5 |
|
6 |
import gradio as gr
|
7 |
|
8 |
-
# two pipelines for normalization only and normalization + human preference
|
9 |
-
|
10 |
# load a pretrained sd model, and then load the LoRA weights
|
11 |
def create_model(weight_path):
|
12 |
model = StableDiffusionPipeline.from_pretrained(
|
13 |
"CompVis/stable-diffusion-v1-4",
|
14 |
torch_dtype=torch.float16,
|
15 |
).to("cuda")
|
|
|
|
|
16 |
model_weight = torch.load(weight_path, map_location='cpu')
|
17 |
unet = model.unet
|
18 |
lora_attn_procs = {}
|
@@ -37,7 +37,7 @@ def create_model(weight_path):
|
|
37 |
unet.load_state_dict(model_weight, strict=False)
|
38 |
return model
|
39 |
|
40 |
-
|
41 |
adapted = create_model("adapted_model.bin")
|
42 |
|
43 |
def inference(prompt):
|
@@ -47,7 +47,7 @@ def inference(prompt):
|
|
47 |
integer_value = int(hex_dig, 16)
|
48 |
# create a pytorch generator based on the prompt
|
49 |
generator = torch.Generator(device='cuda').manual_seed(integer_value % 2147483647)
|
50 |
-
baseline_image =
|
51 |
generator = torch.Generator(device='cuda').manual_seed(integer_value % 2147483647)
|
52 |
adapted_image = adapted(prompt, num_inference_steps=50, generator=generator, negative_prompt="Weird image. ").images[0]
|
53 |
return baseline_image, adapted_image
|
@@ -61,7 +61,6 @@ example_list = [
|
|
61 |
"an aquarium with a galaxy and fish inside floating in space with planet earth in the background, concept art, highly detailed photorealistic, dynamic hdr.",
|
62 |
"a masterpiece landscape, david coulter, mike barr, greg rutkowski, anton fadeev, caspar david friedrich, ferdinand knab, hdr, trending on artstation, cel - shaded, oil painting, professional photography, colorful, complex, epic, realistic colors, hyperdetailed, intricate",
|
63 |
"girl with fox ears, tired eyes, long wavy orange hair, light brown trenchcoat, forest background, focus on face, pretty, moody lighting, painterly, illustration by shigenori soejima ",
|
64 |
-
"a beautiful portrait of anne curtis smith as a shaman, by guweiz and artgerm, ominous, epic fantasy, octopath traveler, afternoon light, rim lighting, unreal engine highly rendered, octane render, volumetric fog, misty, ethereal, 8 k ",
|
65 |
"masterpiece portrait of an aesthetic mage woman, ice spell, 3 0 years old woman, ( katheryn winnick like ), black dynamic hair, wearing silver diadem with blue gems inlays, silver necklace, painting by joachim bergauer and magali villeneuve, atmospheric effects, chaotic blue sparks dynamics in the background, intricate, artstation, fantasy ",
|
66 |
"male character study of male tori spelling, clear faces, screenwriter, introvert, outsider, geek, disturbed, emotional, character sheet, fine details, concept design, contrast, kim jung gi, pixar and da vinci, trending on artstation, 8 k, full body and head, turnaround, front view, back view, ultra wide angle ",
|
67 |
"by yoji shinkawa, concept art of a beautiful woman with purple long hair wearing a large witch hat, ( highly detailed ), flying on broomstick, dynamic lighting, cinematic lighting, neon rim lighting, dreamy night sky background",
|
@@ -88,9 +87,9 @@ with gr.Blocks() as demo:
|
|
88 |
with gr.Row():
|
89 |
with gr.Column():
|
90 |
gr.Markdown('''
|
91 |
-
##
|
92 |
''')
|
93 |
-
|
94 |
with gr.Column():
|
95 |
gr.Markdown('''
|
96 |
## Adaptated model
|
@@ -99,8 +98,8 @@ with gr.Blocks() as demo:
|
|
99 |
gr.Markdown('''
|
100 |
## Example inputs
|
101 |
''')
|
102 |
-
examples = gr.Examples(examples=example_list, label="Examples", inputs=[prompt], cache_examples=True, fn=inference, outputs=[
|
103 |
-
button.click(inference, inputs=prompt, outputs=[
|
104 |
|
105 |
demo.queue(concurrency_count=1)
|
106 |
demo.launch()
|
|
|
5 |
|
6 |
import gradio as gr
|
7 |
|
|
|
|
|
8 |
# load a pretrained sd model, and then load the LoRA weights
|
9 |
def create_model(weight_path):
|
10 |
model = StableDiffusionPipeline.from_pretrained(
|
11 |
"CompVis/stable-diffusion-v1-4",
|
12 |
torch_dtype=torch.float16,
|
13 |
).to("cuda")
|
14 |
+
if not weight_path:
|
15 |
+
return model
|
16 |
model_weight = torch.load(weight_path, map_location='cpu')
|
17 |
unet = model.unet
|
18 |
lora_attn_procs = {}
|
|
|
37 |
unet.load_state_dict(model_weight, strict=False)
|
38 |
return model
|
39 |
|
40 |
+
original = create_model("")
|
41 |
adapted = create_model("adapted_model.bin")
|
42 |
|
43 |
def inference(prompt):
|
|
|
47 |
integer_value = int(hex_dig, 16)
|
48 |
# create a pytorch generator based on the prompt
|
49 |
generator = torch.Generator(device='cuda').manual_seed(integer_value % 2147483647)
|
50 |
+
baseline_image = original(prompt, num_inference_steps=50, generator=generator, negative_prompt="Weird image. ").images[0]
|
51 |
generator = torch.Generator(device='cuda').manual_seed(integer_value % 2147483647)
|
52 |
adapted_image = adapted(prompt, num_inference_steps=50, generator=generator, negative_prompt="Weird image. ").images[0]
|
53 |
return baseline_image, adapted_image
|
|
|
61 |
"an aquarium with a galaxy and fish inside floating in space with planet earth in the background, concept art, highly detailed photorealistic, dynamic hdr.",
|
62 |
"a masterpiece landscape, david coulter, mike barr, greg rutkowski, anton fadeev, caspar david friedrich, ferdinand knab, hdr, trending on artstation, cel - shaded, oil painting, professional photography, colorful, complex, epic, realistic colors, hyperdetailed, intricate",
|
63 |
"girl with fox ears, tired eyes, long wavy orange hair, light brown trenchcoat, forest background, focus on face, pretty, moody lighting, painterly, illustration by shigenori soejima ",
|
|
|
64 |
"masterpiece portrait of an aesthetic mage woman, ice spell, 3 0 years old woman, ( katheryn winnick like ), black dynamic hair, wearing silver diadem with blue gems inlays, silver necklace, painting by joachim bergauer and magali villeneuve, atmospheric effects, chaotic blue sparks dynamics in the background, intricate, artstation, fantasy ",
|
65 |
"male character study of male tori spelling, clear faces, screenwriter, introvert, outsider, geek, disturbed, emotional, character sheet, fine details, concept design, contrast, kim jung gi, pixar and da vinci, trending on artstation, 8 k, full body and head, turnaround, front view, back view, ultra wide angle ",
|
66 |
"by yoji shinkawa, concept art of a beautiful woman with purple long hair wearing a large witch hat, ( highly detailed ), flying on broomstick, dynamic lighting, cinematic lighting, neon rim lighting, dreamy night sky background",
|
|
|
87 |
with gr.Row():
|
88 |
with gr.Column():
|
89 |
gr.Markdown('''
|
90 |
+
## Original Stable Diffusion
|
91 |
''')
|
92 |
+
baseline_output = gr.Image(label="Original Stable Diffusion", type="pil")
|
93 |
with gr.Column():
|
94 |
gr.Markdown('''
|
95 |
## Adaptated model
|
|
|
98 |
gr.Markdown('''
|
99 |
## Example inputs
|
100 |
''')
|
101 |
+
examples = gr.Examples(examples=example_list, label="Examples", inputs=[prompt], cache_examples=True, fn=inference, outputs=[baseline_output, adapted_output])
|
102 |
+
button.click(inference, inputs=prompt, outputs=[baseline_output, adapted_output])
|
103 |
|
104 |
demo.queue(concurrency_count=1)
|
105 |
demo.launch()
|