Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -5,22 +5,16 @@ import spaces
|
|
5 |
import torch
|
6 |
import random
|
7 |
from PIL import Image
|
8 |
-
|
9 |
-
#from kontext_pipeline import FluxKontextPipeline
|
10 |
-
from pipeline_flux_kontext import FluxKontextPipeline
|
11 |
from diffusers import FluxTransformer2DModel
|
12 |
from diffusers.utils import load_image
|
13 |
|
14 |
from huggingface_hub import hf_hub_download
|
15 |
|
16 |
-
|
17 |
-
kontext_path = hf_hub_download(repo_id="diffusers/kontext-v2", filename="dev-opt-2-a-3.safetensors")
|
18 |
|
19 |
MAX_SEED = np.iinfo(np.int32).max
|
20 |
|
21 |
-
transformer = FluxTransformer2DModel.from_single_file(kontext_path, torch_dtype=torch.bfloat16)
|
22 |
-
pipe = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=torch.bfloat16).to("cuda")
|
23 |
-
|
24 |
@spaces.GPU
|
25 |
def infer(input_image, prompt, seed=42, randomize_seed=False, guidance_scale=2.5, progress=gr.Progress(track_tqdm=True)):
|
26 |
|
@@ -28,7 +22,7 @@ def infer(input_image, prompt, seed=42, randomize_seed=False, guidance_scale=2.5
|
|
28 |
seed = random.randint(0, MAX_SEED)
|
29 |
|
30 |
input_image = input_image.convert("RGB")
|
31 |
-
prompt_with_template = f"
|
32 |
|
33 |
image = pipe(
|
34 |
image=input_image,
|
@@ -50,8 +44,10 @@ css="""
|
|
50 |
with gr.Blocks(css=css) as demo:
|
51 |
|
52 |
with gr.Column(elem_id="col-container"):
|
53 |
-
gr.Markdown(f"""# FLUX.1 Kontext [dev] Relight
|
54 |
""")
|
|
|
|
|
55 |
|
56 |
with gr.Row():
|
57 |
with gr.Column():
|
|
|
5 |
import torch
|
6 |
import random
|
7 |
from PIL import Image
|
8 |
+
from diffusers import FluxKontextPipeline
|
|
|
|
|
9 |
from diffusers import FluxTransformer2DModel
|
10 |
from diffusers.utils import load_image
|
11 |
|
12 |
from huggingface_hub import hf_hub_download
|
13 |
|
14 |
+
pipe = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16).to("cuda")
|
|
|
15 |
|
16 |
MAX_SEED = np.iinfo(np.int32).max
|
17 |
|
|
|
|
|
|
|
18 |
@spaces.GPU
|
19 |
def infer(input_image, prompt, seed=42, randomize_seed=False, guidance_scale=2.5, progress=gr.Progress(track_tqdm=True)):
|
20 |
|
|
|
22 |
seed = random.randint(0, MAX_SEED)
|
23 |
|
24 |
input_image = input_image.convert("RGB")
|
25 |
+
prompt_with_template = f"Change the lighting conditions in this image to {prompt}. Modify or replace the background as needed to create an environment that naturally produces these lighting conditions, while maintaining the foreground subject. Lighting determines how bright or dark different parts of the image appear, where shadows fall, and how colors look. When you relight an image, you're simulating what the photo would look like if it were taken under different lighting conditions with an appropriate background setting."
|
26 |
|
27 |
image = pipe(
|
28 |
image=input_image,
|
|
|
44 |
with gr.Blocks(css=css) as demo:
|
45 |
|
46 |
with gr.Column(elem_id="col-container"):
|
47 |
+
gr.Markdown(f"""# FLUX.1 Kontext [dev] Relight 💡
|
48 |
""")
|
49 |
+
gr.Markdown(f"""Kontext[dev] used for object relighting ✨
|
50 |
+
""")
|
51 |
|
52 |
with gr.Row():
|
53 |
with gr.Column():
|