Spaces:
Sleeping
Sleeping
Commit
·
3ed80a5
1
Parent(s):
5f0118b
Initial dump
Browse files- .gitignore +9 -0
- app.py +150 -0
- requirements.txt +6 -0
.gitignore
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Custom for repository
|
2 |
+
dev/
|
3 |
+
|
4 |
+
# Byte-compiled / optimized / DLL files
|
5 |
+
*__pycache__/
|
6 |
+
*.py[cod]
|
7 |
+
|
8 |
+
# VS Code
|
9 |
+
.vscode/
|
app.py
ADDED
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
|
7 |
+
|
8 |
+
MAX_IMAGES = 4
|
9 |
+
|
10 |
+
|
11 |
+
def generate_images(
|
12 |
+
hp_num: int,
|
13 |
+
attack_num: int,
|
14 |
+
defense_num: int,
|
15 |
+
sp_attack_num: int,
|
16 |
+
sp_defense_num: int,
|
17 |
+
speed_num: int,
|
18 |
+
) -> list:
|
19 |
+
"""Generates a sprite based on the input stats.
|
20 |
+
|
21 |
+
Parameters
|
22 |
+
----------
|
23 |
+
|
24 |
+
Returns
|
25 |
+
-------
|
26 |
+
list
|
27 |
+
List of PIL images.
|
28 |
+
"""
|
29 |
+
# Initalize the images list
|
30 |
+
images_list = []
|
31 |
+
# Calculate the base total
|
32 |
+
base_total = (
|
33 |
+
hp_num + attack_num + defense_num + sp_attack_num + sp_defense_num + speed_num
|
34 |
+
)
|
35 |
+
# Create the text prompt
|
36 |
+
prompt = f"type1: fire, type2: ghost, base_total: {base_total}, hp: {hp_num}, attack: {attack_num}, defense: {defense_num}, sp_attack: {sp_attack_num}, sp_defense: {sp_defense_num}, speed: {speed_num}"
|
37 |
+
# Generate the images
|
38 |
+
for _ in range(MAX_IMAGES):
|
39 |
+
image = pipe(
|
40 |
+
prompt,
|
41 |
+
height=288,
|
42 |
+
width=288,
|
43 |
+
num_inference_steps=25,
|
44 |
+
guidance_scale=7.5,
|
45 |
+
cross_attention_kwargs={"scale": 1.0},
|
46 |
+
).images[0]
|
47 |
+
images_list.append(Image.fromarray(np.array(image)))
|
48 |
+
|
49 |
+
return images_list
|
50 |
+
|
51 |
+
|
52 |
+
# Create the demo interface
|
53 |
+
demo = gr.Blocks()
|
54 |
+
|
55 |
+
# Set the models to load
|
56 |
+
model_base = "stabilityai/stable-diffusion-2-base"
|
57 |
+
lora_model_path = "michaelriedl/MonsterForgeFusion-sd-2-base"
|
58 |
+
|
59 |
+
# Create the pipeline
|
60 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
61 |
+
model_base, torch_dtype=torch.float16, use_safetensors=False, local_files_only=False
|
62 |
+
)
|
63 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
64 |
+
pipe.unet.load_attn_procs(lora_model_path)
|
65 |
+
|
66 |
+
# Create the interface
|
67 |
+
with demo:
|
68 |
+
gr.HTML(
|
69 |
+
"""
|
70 |
+
<div style="text-align: center; margin: 0 auto;">
|
71 |
+
<p style="margin-bottom: 14px; line-height: 23px;">
|
72 |
+
Gradio demo for MonsterForgeFusion models. This was built with LoRA fine-tuning of Stable Diffusion models.
|
73 |
+
</p>
|
74 |
+
</div>
|
75 |
+
"""
|
76 |
+
)
|
77 |
+
with gr.Column():
|
78 |
+
with gr.Row():
|
79 |
+
gallery = gr.Gallery(
|
80 |
+
columns=4,
|
81 |
+
object_fit="scale-down",
|
82 |
+
)
|
83 |
+
with gr.Row():
|
84 |
+
hp_num = gr.Slider(
|
85 |
+
minimum=1,
|
86 |
+
maximum=100,
|
87 |
+
value=50,
|
88 |
+
step=1,
|
89 |
+
label="HP",
|
90 |
+
)
|
91 |
+
attack_num = gr.Slider(
|
92 |
+
minimum=1,
|
93 |
+
maximum=100,
|
94 |
+
value=50,
|
95 |
+
step=1,
|
96 |
+
label="Attack",
|
97 |
+
)
|
98 |
+
with gr.Row():
|
99 |
+
defense_num = gr.Slider(
|
100 |
+
minimum=1,
|
101 |
+
maximum=100,
|
102 |
+
value=50,
|
103 |
+
step=1,
|
104 |
+
label="Defense",
|
105 |
+
)
|
106 |
+
sp_attack_num = gr.Slider(
|
107 |
+
minimum=1,
|
108 |
+
maximum=100,
|
109 |
+
value=50,
|
110 |
+
step=1,
|
111 |
+
label="Special Attack",
|
112 |
+
)
|
113 |
+
with gr.Row():
|
114 |
+
sp_defense_num = gr.Slider(
|
115 |
+
minimum=1,
|
116 |
+
maximum=100,
|
117 |
+
value=50,
|
118 |
+
step=1,
|
119 |
+
label="Special Defense",
|
120 |
+
)
|
121 |
+
speed_num = gr.Slider(
|
122 |
+
minimum=1,
|
123 |
+
maximum=100,
|
124 |
+
value=50,
|
125 |
+
step=1,
|
126 |
+
label="Speed",
|
127 |
+
)
|
128 |
+
gen_btn_small = gr.Button("Generate")
|
129 |
+
gen_btn_small.click(
|
130 |
+
fn=generate_images,
|
131 |
+
inputs=[
|
132 |
+
hp_num,
|
133 |
+
attack_num,
|
134 |
+
defense_num,
|
135 |
+
sp_attack_num,
|
136 |
+
sp_defense_num,
|
137 |
+
speed_num,
|
138 |
+
],
|
139 |
+
outputs=gallery,
|
140 |
+
)
|
141 |
+
gr.HTML(
|
142 |
+
"""
|
143 |
+
<div class="footer">
|
144 |
+
<div style='text-align: center;'>MonsterForgeFusion by <a href='https://michaelriedl.com/' target='_blank'>Michael Riedl</a></div>
|
145 |
+
</div>
|
146 |
+
"""
|
147 |
+
)
|
148 |
+
|
149 |
+
# Launch the interface
|
150 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
numpy
|
4 |
+
Pillow
|
5 |
+
einops>=0.3
|
6 |
+
kornia>=0.5.4
|