Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -15,11 +15,13 @@ from pytorch_lightning import seed_everything
|
|
15 |
from omegaconf import OmegaConf
|
16 |
from einops import rearrange, repeat
|
17 |
from tqdm import tqdm
|
18 |
-
from diffusers import
|
19 |
import gradio as gr
|
20 |
import shutil
|
21 |
import tempfile
|
22 |
from functools import partial
|
|
|
|
|
23 |
|
24 |
from src.utils.train_util import instantiate_from_config
|
25 |
from src.utils.camera_util import (
|
@@ -69,11 +71,24 @@ if cuda_path:
|
|
69 |
else:
|
70 |
print("CUDA installation not found")
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
# Load 3D generation models
|
79 |
config_path = 'configs/instant-mesh-large.yaml'
|
@@ -135,18 +150,20 @@ def preprocess(input_image, do_remove_background):
|
|
135 |
input_image = resize_foreground(input_image, 0.85)
|
136 |
return input_image
|
137 |
|
|
|
|
|
138 |
@spaces.GPU
|
139 |
def generate_flux_image(prompt, height, width, steps, scales, seed):
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
|
151 |
@spaces.GPU
|
152 |
def generate_mvs(input_image, sample_steps, sample_seed):
|
|
|
15 |
from omegaconf import OmegaConf
|
16 |
from einops import rearrange, repeat
|
17 |
from tqdm import tqdm
|
18 |
+
from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler
|
19 |
import gradio as gr
|
20 |
import shutil
|
21 |
import tempfile
|
22 |
from functools import partial
|
23 |
+
from optimum.quanto import quantize, qfloat8, freeze
|
24 |
+
from flux_8bit_lora import FluxPipeline
|
25 |
|
26 |
from src.utils.train_util import instantiate_from_config
|
27 |
from src.utils.camera_util import (
|
|
|
71 |
else:
|
72 |
print("CUDA installation not found")
|
73 |
|
74 |
+
|
75 |
+
|
76 |
+
base_model = "black-forest-labs/FLUX.1-dev"
|
77 |
+
pipe = FluxPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16, token=huggingface_token)
|
78 |
+
|
79 |
+
print('Loading and fusing lora, please wait...')
|
80 |
+
pipe.load_lora_weights(hf_hub_download("gokaygokay/Flux-Game-Assets-LoRA-v2", "game_asst.safetensors"))
|
81 |
+
# We need this scaling because SimpleTuner fixes the alpha to 16, might be fixed later in diffusers
|
82 |
+
# See https://github.com/huggingface/diffusers/issues/9134
|
83 |
+
pipe.fuse_lora(lora_scale=1.)
|
84 |
+
pipe.unload_lora_weights()
|
85 |
+
|
86 |
+
print('Quantizing, please wait...')
|
87 |
+
quantize(pipe.transformer, qfloat8)
|
88 |
+
freeze(pipe.transformer)
|
89 |
+
print('Model quantized!')
|
90 |
+
pipe.to('cuda')
|
91 |
+
|
92 |
|
93 |
# Load 3D generation models
|
94 |
config_path = 'configs/instant-mesh-large.yaml'
|
|
|
150 |
input_image = resize_foreground(input_image, 0.85)
|
151 |
return input_image
|
152 |
|
153 |
+
ts_cutoff = 2
|
154 |
+
|
155 |
@spaces.GPU
|
156 |
def generate_flux_image(prompt, height, width, steps, scales, seed):
|
157 |
+
return pipe(
|
158 |
+
prompt=prompt,
|
159 |
+
width=int(height),
|
160 |
+
height=int(width),
|
161 |
+
num_inference_steps=int(steps),
|
162 |
+
generator=torch.Generator().manual_seed(int(seed)),
|
163 |
+
guidance_scale=float(scales),
|
164 |
+
timestep_to_start_cfg=ts_cutoff,
|
165 |
+
).images[0]
|
166 |
+
|
167 |
|
168 |
@spaces.GPU
|
169 |
def generate_mvs(input_image, sample_steps, sample_seed):
|