Spaces:
Running on Zero
Running on Zero
Commit ·
93a524b
1
Parent(s): 19cdd40
add torchvision to requirement
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ import os
|
|
| 14 |
|
| 15 |
dtype = torch.bfloat16
|
| 16 |
token = os.environ.get("HF_TOKEN")
|
| 17 |
-
|
| 18 |
pipe = FluxPipeline.from_pretrained(
|
| 19 |
"black-forest-labs/FLUX.1-dev",
|
| 20 |
torch_dtype=dtype,
|
|
@@ -24,7 +24,7 @@ pipe = pipe.to("cuda")
|
|
| 24 |
|
| 25 |
|
| 26 |
@spaces.GPU
|
| 27 |
-
def process_image_and_text(image, scale, seed, text
|
| 28 |
set_seed(seed)
|
| 29 |
blended_attn_procs = {}
|
| 30 |
for name, _ in pipe.transformer.attn_processors.items():
|
|
@@ -52,9 +52,8 @@ def process_image_and_text(image, scale, seed, text, pipe):
|
|
| 52 |
key_changed_blended_attn_weights[changed_key] = value.to(dtype)
|
| 53 |
|
| 54 |
missing_keys, unexpected_keys = pipe.transformer.load_state_dict(key_changed_blended_attn_weights, strict=False)
|
| 55 |
-
|
| 56 |
pipe = pipe.to("cuda")
|
| 57 |
-
|
| 58 |
# image = Image.open(img_path).convert('RGB')
|
| 59 |
image = resize_and_add_margin(image, target_size=512)
|
| 60 |
|
|
@@ -145,7 +144,7 @@ header = """
|
|
| 145 |
"""
|
| 146 |
|
| 147 |
|
| 148 |
-
def create_app(
|
| 149 |
|
| 150 |
with gr.Blocks() as app:
|
| 151 |
gr.Markdown(header, elem_id="header")
|
|
@@ -178,7 +177,7 @@ def create_app(pipe):
|
|
| 178 |
|
| 179 |
submit_btn.click(
|
| 180 |
fn=process_image_and_text,
|
| 181 |
-
inputs=[original_image, scale, seed, text
|
| 182 |
outputs=output_image,
|
| 183 |
)
|
| 184 |
|
|
@@ -186,4 +185,4 @@ def create_app(pipe):
|
|
| 186 |
|
| 187 |
|
| 188 |
if __name__ == "__main__":
|
| 189 |
-
create_app(
|
|
|
|
| 14 |
|
| 15 |
dtype = torch.bfloat16
|
| 16 |
token = os.environ.get("HF_TOKEN")
|
| 17 |
+
pipe = None
|
| 18 |
pipe = FluxPipeline.from_pretrained(
|
| 19 |
"black-forest-labs/FLUX.1-dev",
|
| 20 |
torch_dtype=dtype,
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
@spaces.GPU
|
| 27 |
+
def process_image_and_text(image, scale, seed, text):
|
| 28 |
set_seed(seed)
|
| 29 |
blended_attn_procs = {}
|
| 30 |
for name, _ in pipe.transformer.attn_processors.items():
|
|
|
|
| 52 |
key_changed_blended_attn_weights[changed_key] = value.to(dtype)
|
| 53 |
|
| 54 |
missing_keys, unexpected_keys = pipe.transformer.load_state_dict(key_changed_blended_attn_weights, strict=False)
|
|
|
|
| 55 |
pipe = pipe.to("cuda")
|
| 56 |
+
|
| 57 |
# image = Image.open(img_path).convert('RGB')
|
| 58 |
image = resize_and_add_margin(image, target_size=512)
|
| 59 |
|
|
|
|
| 144 |
"""
|
| 145 |
|
| 146 |
|
| 147 |
+
def create_app():
|
| 148 |
|
| 149 |
with gr.Blocks() as app:
|
| 150 |
gr.Markdown(header, elem_id="header")
|
|
|
|
| 177 |
|
| 178 |
submit_btn.click(
|
| 179 |
fn=process_image_and_text,
|
| 180 |
+
inputs=[original_image, scale, seed, text],
|
| 181 |
outputs=output_image,
|
| 182 |
)
|
| 183 |
|
|
|
|
| 185 |
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|
| 188 |
+
create_app().launch(debug=True, ssr_mode=False)
|