Spaces:
Sleeping
Sleeping
Update space
Browse files- app.py +4 -1
- model/animagine_xl.py +25 -3
- model/output_waifu_cpu.png +3 -0
- model/waifu.py +33 -8
app.py
CHANGED
|
@@ -9,6 +9,9 @@ from model.waifu import generate_waifu
|
|
| 9 |
from Text2Long_text import generate_korean_story
|
| 10 |
|
| 11 |
# ๋ชจ๋ธ ํจ์ ๋งคํ
|
|
|
|
|
|
|
|
|
|
| 12 |
MODEL_FUNCTIONS = {
|
| 13 |
"Animagine XL": generate_animagine_xl,
|
| 14 |
"Animesai": generate_animesai,
|
|
@@ -16,7 +19,7 @@ MODEL_FUNCTIONS = {
|
|
| 16 |
"Ghibli": generate_ghibli,
|
| 17 |
"Realistic": generate_realistic,
|
| 18 |
"SD Turbo": generate_sd_turbo,
|
| 19 |
-
"Waifu Diffusion": generate_waifu,
|
| 20 |
"ํ๊ตญ์ด ๊ธด ์ด์ผ๊ธฐ ์์ฑ": lambda prompt: generate_korean_story(prompt, max_length=100),
|
| 21 |
}
|
| 22 |
|
|
|
|
| 9 |
from Text2Long_text import generate_korean_story
|
| 10 |
|
| 11 |
# ๋ชจ๋ธ ํจ์ ๋งคํ
|
| 12 |
+
|
| 13 |
+
model_id = "hakurei/waifu-diffusion"
|
| 14 |
+
|
| 15 |
MODEL_FUNCTIONS = {
|
| 16 |
"Animagine XL": generate_animagine_xl,
|
| 17 |
"Animesai": generate_animesai,
|
|
|
|
| 19 |
"Ghibli": generate_ghibli,
|
| 20 |
"Realistic": generate_realistic,
|
| 21 |
"SD Turbo": generate_sd_turbo,
|
| 22 |
+
"Waifu Diffusion": generate_waifu(model_id),
|
| 23 |
"ํ๊ตญ์ด ๊ธด ์ด์ผ๊ธฐ ์์ฑ": lambda prompt: generate_korean_story(prompt, max_length=100),
|
| 24 |
}
|
| 25 |
|
model/animagine_xl.py
CHANGED
|
@@ -10,14 +10,36 @@ def generate_animagine_xl(prompt: str):
|
|
| 10 |
variant="fp16"
|
| 11 |
)
|
| 12 |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 13 |
-
|
| 14 |
-
pipe = pipe.to(device)
|
| 15 |
image = pipe(prompt=prompt, width=1024, height=1024).images[0]
|
| 16 |
image.save("output_animagine_xl.png")
|
| 17 |
print("โ
์ ์ฅ ์๋ฃ: output_animagine_xl.png")
|
| 18 |
return image
|
| 19 |
|
| 20 |
-
|
| 21 |
if __name__ == "__main__":
|
| 22 |
prompt = "๊ทธ๋
๋ฅผ ๋ฐ๋ผ๋ณด๋ ํ ๋จ์์ ์ผ๋ง"
|
| 23 |
generate_animagine_xl(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
variant="fp16"
|
| 11 |
)
|
| 12 |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 13 |
+
pipe = pipe.to("cuda")
|
|
|
|
| 14 |
image = pipe(prompt=prompt, width=1024, height=1024).images[0]
|
| 15 |
image.save("output_animagine_xl.png")
|
| 16 |
print("โ
์ ์ฅ ์๋ฃ: output_animagine_xl.png")
|
| 17 |
return image
|
| 18 |
|
|
|
|
| 19 |
if __name__ == "__main__":
|
| 20 |
prompt = "๊ทธ๋
๋ฅผ ๋ฐ๋ผ๋ณด๋ ํ ๋จ์์ ์ผ๋ง"
|
| 21 |
generate_animagine_xl(prompt)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
| 25 |
+
# import torch
|
| 26 |
+
|
| 27 |
+
# def generate_animagine_xl(prompt: str):
|
| 28 |
+
# model_id = "Linaqruf/animagine-xl"
|
| 29 |
+
# use_fp16 = torch.cuda.is_available()
|
| 30 |
+
# pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 31 |
+
# model_id,
|
| 32 |
+
# torch_dtype=torch.float16 if use_fp16 else torch.float32,
|
| 33 |
+
# use_safetensors=True,
|
| 34 |
+
# variant="fp16"
|
| 35 |
+
# )
|
| 36 |
+
# pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 37 |
+
# device = "cuda" if use_fp16 else "cpu"
|
| 38 |
+
# pipe = pipe.to(device)
|
| 39 |
+
# image = pipe(prompt=prompt, width=1024, height=1024).images[0]
|
| 40 |
+
# image.save("output_animagine_xl.png")
|
| 41 |
+
# return image
|
| 42 |
+
|
| 43 |
+
# if __name__ == "__main__":
|
| 44 |
+
# prompt = "๊ทธ๋
๋ฅผ ๋ฐ๋ผ๋ณด๋ ํ ๋จ์์ ์ผ๋ง"
|
| 45 |
+
# generate_animagine_xl(prompt)
|
model/output_waifu_cpu.png
ADDED
|
Git LFS Details
|
model/waifu.py
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from diffusers import StableDiffusionPipeline
|
| 2 |
import torch
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
model_id = "hakurei/waifu-diffusion"
|
| 6 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 7 |
model_id,
|
| 8 |
-
torch_dtype=torch.
|
| 9 |
-
use_safetensors=False
|
| 10 |
-
revision="fp16"
|
| 11 |
-
).to("
|
|
|
|
| 12 |
|
| 13 |
image = pipe(prompt=prompt).images[0]
|
| 14 |
return image
|
| 15 |
|
|
|
|
| 16 |
if __name__ == "__main__":
|
| 17 |
prompt = '๊ทธ๋
๋ฅผ ๋ฐ๋ผ๋ณด๋ ํ ๋จ์์ ์ผ๋ง'
|
| 18 |
image = generate_waifu(prompt)
|
| 19 |
-
image.save("
|
| 20 |
-
print("โ
์ ์ฅ ์๋ฃ:
|
| 21 |
-
image.show()
|
|
|
|
| 1 |
+
# from diffusers import StableDiffusionPipeline
|
| 2 |
+
# import torch
|
| 3 |
+
|
| 4 |
+
# def generate_waifu(prompt: str):
|
| 5 |
+
# model_id = "hakurei/waifu-diffusion"
|
| 6 |
+
# pipe = StableDiffusionPipeline.from_pretrained(
|
| 7 |
+
# model_id,
|
| 8 |
+
# torch_dtype=torch.float16,
|
| 9 |
+
# use_safetensors=False,
|
| 10 |
+
# revision="fp16"
|
| 11 |
+
# ).to("cuda")
|
| 12 |
+
|
| 13 |
+
# image = pipe(prompt=prompt).images[0]
|
| 14 |
+
# return image
|
| 15 |
+
|
| 16 |
+
# if __name__ == "__main__":
|
| 17 |
+
# prompt = '๊ทธ๋
๋ฅผ ๋ฐ๋ผ๋ณด๋ ํ ๋จ์์ ์ผ๋ง'
|
| 18 |
+
# image = generate_waifu(prompt)
|
| 19 |
+
# image.save("output_waifu.png")
|
| 20 |
+
# print("โ
์ ์ฅ ์๋ฃ: output_waifu.png")
|
| 21 |
+
# image.show()
|
| 22 |
+
|
| 23 |
from diffusers import StableDiffusionPipeline
|
| 24 |
import torch
|
| 25 |
|
| 26 |
+
|
| 27 |
+
def generate_waifu(prompt: str, model_id):
|
| 28 |
model_id = "hakurei/waifu-diffusion"
|
| 29 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 30 |
model_id,
|
| 31 |
+
torch_dtype=torch.float32, # CPU๋ float32๋ง ์ง์
|
| 32 |
+
use_safetensors=False
|
| 33 |
+
# revision=None # revision="fp16" ์ญ์
|
| 34 |
+
).to("cpu") # ๋ฐ๋์ CPU๋ก ์ง์
|
| 35 |
+
|
| 36 |
|
| 37 |
image = pipe(prompt=prompt).images[0]
|
| 38 |
return image
|
| 39 |
|
| 40 |
+
|
| 41 |
if __name__ == "__main__":
|
| 42 |
prompt = '๊ทธ๋
๋ฅผ ๋ฐ๋ผ๋ณด๋ ํ ๋จ์์ ์ผ๋ง'
|
| 43 |
image = generate_waifu(prompt)
|
| 44 |
+
image.save("output_waifu_cpu.png")
|
| 45 |
+
print("โ
์ ์ฅ ์๋ฃ: output_waifu_cpu.png")
|
| 46 |
+
image.show()
|