Spaces:
Running
on
Zero
Running
on
Zero
PommesPeter
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -43,38 +43,6 @@ description = """
|
|
43 |
|
44 |
hf_token = os.environ['HF_TOKEN']
|
45 |
|
46 |
-
examples = [
|
47 |
-
["👽🤖👹👻"],
|
48 |
-
["孤舟蓑笠翁"],
|
49 |
-
["两只黄鹂鸣翠柳"],
|
50 |
-
["大漠孤烟直,长河落日圆"],
|
51 |
-
["秋风起兮白云飞,草木黄落兮雁南归"],
|
52 |
-
["도쿄 타워, 최고 품질의 우키요에, 에도 시대"],
|
53 |
-
["味噌ラーメン, 最高品質の浮世絵、江戸時代。"],
|
54 |
-
["東京タワー、最高品質の浮世絵、江戸時代。"],
|
55 |
-
["Astronaut on Mars During sunset"],
|
56 |
-
["Tour de Tokyo, estampes ukiyo-e de la plus haute qualité, période Edo"],
|
57 |
-
["🐔 playing 🏀"],
|
58 |
-
["☃️ with 🌹 in the ❄️"],
|
59 |
-
["🐶 wearing 😎 flying on 🌈 "],
|
60 |
-
["A small 🍎 and 🍊 with 😁 emoji in the Sahara desert"],
|
61 |
-
["Токийская башня, лучшие укиё-э, период Эдо"],
|
62 |
-
["Tokio-Turm, hochwertigste Ukiyo-e, Edo-Zeit"],
|
63 |
-
["A scared cute rabbit in Happy Tree Friends style and punk vibe."], # noqa
|
64 |
-
["A humanoid eagle soldier of the First World War."], # noqa
|
65 |
-
["A cute Christmas mockup on an old wooden industrial desk table with Christmas decorations and bokeh lights in the background."],
|
66 |
-
["A front view of a romantic flower shop in France filled with various blooming flowers including lavenders and roses."],
|
67 |
-
["An old man, portrayed as a retro superhero, stands in the streets of New York City at night"],
|
68 |
-
["many trees are surrounded by a lake in autumn colors, in the style of nature-inspired imagery, havencore, brightly colored, dark white and dark orange, bright primary colors, environmental activism, forestpunk --ar 64:51"],
|
69 |
-
["A fluffy mouse holding a watermelon, in a magical and colorful setting, illustrated in the style of Hayao Miyazaki anime by Studio Ghibli."],
|
70 |
-
["Inka warrior with a war make up, medium shot, natural light, Award winning wildlife photography, hyperrealistic, 8k resolution, --ar 9:16"],
|
71 |
-
["Character of lion in style of saiyan, mafia, gangsta, citylights background, Hyper detailed, hyper realistic, unreal engine ue5, cgi 3d, cinematic shot, 8k"],
|
72 |
-
["In the sky above, a giant, whimsical cloud shaped like the 😊 emoji casts a soft, golden light over the scene"],
|
73 |
-
["Cyberpunk eagle, neon ambiance, abstract black oil, gear mecha, detailed acrylic, grunge, intricate complexity, rendered in unreal engine 5, photorealistic, 8k"],
|
74 |
-
["close-up photo of a beautiful red rose breaking through a cube made of ice , splintered cracked ice surface, frosted colors, blood dripping from rose, melting ice, Valentine’s Day vibes, cinematic, sharp focus, intricate, cinematic, dramatic light"],
|
75 |
-
["3D cartoon Fox Head with Human Body, Wearing Iridescent Holographic Liquid Texture & Translucent Material Sun Protective Shirt, Boss Feel, Nike or Addidas Sun Protective Shirt, WitchPunk, Y2K Style, Green and blue, Blue, Metallic Feel, Strong Reflection, plain background, no background, pure single color background, Digital Fashion, Surreal Futurism, Supreme Kong NFT Artwork Style, disney style, headshot photography for portrait studio shoot, fashion editorial aesthetic, high resolution in the style of HAPE PRIME NFT, NFT 3D IP Feel, Bored Ape Yacht Club NFT project Feel, high detail, fine luster, 3D render, oc render, best quality, 8K, bright, front lighting, Face Shot, fine luster, ultra detailed"],
|
76 |
-
]
|
77 |
-
|
78 |
class ModelFailure:
|
79 |
pass
|
80 |
|
@@ -116,8 +84,7 @@ def encode_prompt(
|
|
116 |
return prompt_embeds, prompt_masks
|
117 |
|
118 |
|
119 |
-
|
120 |
-
def model_main(args, master_port, rank, request_queue, response_queue):
|
121 |
# import here to avoid huggingface Tokenizer parallelism warnings
|
122 |
from diffusers.models import AutoencoderKL
|
123 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
@@ -199,7 +166,16 @@ def model_main(args, master_port, rank, request_queue, response_queue):
|
|
199 |
model.load_state_dict(ckpt, strict=True)
|
200 |
|
201 |
# mp_barrier.wait()
|
|
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
with torch.autocast("cuda", dtype):
|
204 |
while True:
|
205 |
(
|
@@ -465,6 +441,7 @@ def main():
|
|
465 |
response_queue = Queue()
|
466 |
# mp_barrier = mp.Barrier(args.num_gpus + 1)
|
467 |
for i in range(args.num_gpus):
|
|
|
468 |
request_queues.append(Queue())
|
469 |
generation_kwargs = dict(
|
470 |
args=args,
|
@@ -472,6 +449,10 @@ def main():
|
|
472 |
rank=i,
|
473 |
request_queue=request_queues[i],
|
474 |
response_queue=response_queue if i == 0 else None,
|
|
|
|
|
|
|
|
|
475 |
)
|
476 |
thread = Thread(target=model_main, kwargs=generation_kwargs)
|
477 |
thread.start()
|
@@ -568,7 +549,37 @@ def main():
|
|
568 |
|
569 |
with gr.Row():
|
570 |
gr.Examples(
|
571 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
572 |
[cap],
|
573 |
label="Examples",
|
574 |
)
|
|
|
43 |
|
44 |
hf_token = os.environ['HF_TOKEN']
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
class ModelFailure:
|
47 |
pass
|
48 |
|
|
|
84 |
return prompt_embeds, prompt_masks
|
85 |
|
86 |
|
87 |
+
def load_model(args, master_port, rank):
|
|
|
88 |
# import here to avoid huggingface Tokenizer parallelism warnings
|
89 |
from diffusers.models import AutoencoderKL
|
90 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
166 |
model.load_state_dict(ckpt, strict=True)
|
167 |
|
168 |
# mp_barrier.wait()
|
169 |
+
return text_encoder, tokenizer, vae, model
|
170 |
|
171 |
+
|
172 |
+
@torch.no_grad()
|
173 |
+
def model_main(args, master_port, rank, request_queue, response_queue, text_encoder, tokenizer, vae, model):
|
174 |
+
dtype = {"bf16": torch.bfloat16, "fp16": torch.float16, "fp32": torch.float32}[
|
175 |
+
args.precision
|
176 |
+
]
|
177 |
+
train_args = torch.load(os.path.join(args.ckpt, "model_args.pth"))
|
178 |
+
|
179 |
with torch.autocast("cuda", dtype):
|
180 |
while True:
|
181 |
(
|
|
|
441 |
response_queue = Queue()
|
442 |
# mp_barrier = mp.Barrier(args.num_gpus + 1)
|
443 |
for i in range(args.num_gpus):
|
444 |
+
text_encoder, tokenizer, vae, model = load_model(args, master_port, i)
|
445 |
request_queues.append(Queue())
|
446 |
generation_kwargs = dict(
|
447 |
args=args,
|
|
|
449 |
rank=i,
|
450 |
request_queue=request_queues[i],
|
451 |
response_queue=response_queue if i == 0 else None,
|
452 |
+
text_encoder=text_encoder,
|
453 |
+
tokenizer=tokenizer,
|
454 |
+
vae=vae,
|
455 |
+
model=model
|
456 |
)
|
457 |
thread = Thread(target=model_main, kwargs=generation_kwargs)
|
458 |
thread.start()
|
|
|
549 |
|
550 |
with gr.Row():
|
551 |
gr.Examples(
|
552 |
+
[
|
553 |
+
["👽🤖👹👻"],
|
554 |
+
["孤舟蓑笠翁"],
|
555 |
+
["两只黄鹂鸣翠柳"],
|
556 |
+
["大漠孤烟直,长河落日圆"],
|
557 |
+
["秋风起兮白云飞,草木黄落兮雁南归"],
|
558 |
+
["도쿄 타워, 최고 품질의 우키요에, 에도 시대"],
|
559 |
+
["味噌ラーメン, 最高品質の浮世絵、江戸時代。"],
|
560 |
+
["東京タワー、最高品質の浮世絵、江戸時代。"],
|
561 |
+
["Astronaut on Mars During sunset"],
|
562 |
+
["Tour de Tokyo, estampes ukiyo-e de la plus haute qualité, période Edo"],
|
563 |
+
["🐔 playing 🏀"],
|
564 |
+
["☃️ with 🌹 in the ❄️"],
|
565 |
+
["🐶 wearing 😎 flying on 🌈 "],
|
566 |
+
["A small 🍎 and 🍊 with 😁 emoji in the Sahara desert"],
|
567 |
+
["Токийская башня, лучшие укиё-э, период Эдо"],
|
568 |
+
["Tokio-Turm, hochwertigste Ukiyo-e, Edo-Zeit"],
|
569 |
+
["A scared cute rabbit in Happy Tree Friends style and punk vibe."], # noqa
|
570 |
+
["A humanoid eagle soldier of the First World War."], # noqa
|
571 |
+
["A cute Christmas mockup on an old wooden industrial desk table with Christmas decorations and bokeh lights in the background."],
|
572 |
+
["A front view of a romantic flower shop in France filled with various blooming flowers including lavenders and roses."],
|
573 |
+
["An old man, portrayed as a retro superhero, stands in the streets of New York City at night"],
|
574 |
+
["many trees are surrounded by a lake in autumn colors, in the style of nature-inspired imagery, havencore, brightly colored, dark white and dark orange, bright primary colors, environmental activism, forestpunk --ar 64:51"],
|
575 |
+
["A fluffy mouse holding a watermelon, in a magical and colorful setting, illustrated in the style of Hayao Miyazaki anime by Studio Ghibli."],
|
576 |
+
["Inka warrior with a war make up, medium shot, natural light, Award winning wildlife photography, hyperrealistic, 8k resolution, --ar 9:16"],
|
577 |
+
["Character of lion in style of saiyan, mafia, gangsta, citylights background, Hyper detailed, hyper realistic, unreal engine ue5, cgi 3d, cinematic shot, 8k"],
|
578 |
+
["In the sky above, a giant, whimsical cloud shaped like the 😊 emoji casts a soft, golden light over the scene"],
|
579 |
+
["Cyberpunk eagle, neon ambiance, abstract black oil, gear mecha, detailed acrylic, grunge, intricate complexity, rendered in unreal engine 5, photorealistic, 8k"],
|
580 |
+
["close-up photo of a beautiful red rose breaking through a cube made of ice , splintered cracked ice surface, frosted colors, blood dripping from rose, melting ice, Valentine’s Day vibes, cinematic, sharp focus, intricate, cinematic, dramatic light"],
|
581 |
+
["3D cartoon Fox Head with Human Body, Wearing Iridescent Holographic Liquid Texture & Translucent Material Sun Protective Shirt, Boss Feel, Nike or Addidas Sun Protective Shirt, WitchPunk, Y2K Style, Green and blue, Blue, Metallic Feel, Strong Reflection, plain background, no background, pure single color background, Digital Fashion, Surreal Futurism, Supreme Kong NFT Artwork Style, disney style, headshot photography for portrait studio shoot, fashion editorial aesthetic, high resolution in the style of HAPE PRIME NFT, NFT 3D IP Feel, Bored Ape Yacht Club NFT project Feel, high detail, fine luster, 3D render, oc render, best quality, 8K, bright, front lighting, Face Shot, fine luster, ultra detailed"],
|
582 |
+
],
|
583 |
[cap],
|
584 |
label="Examples",
|
585 |
)
|