Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
6 |
-
from diffusers import
|
7 |
import random
|
8 |
import numpy as np
|
9 |
import os
|
@@ -22,8 +22,8 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
22 |
dtype = torch.bfloat16
|
23 |
huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
|
24 |
|
25 |
-
# Load FLUX img2img pipeline
|
26 |
-
pipe =
|
27 |
"black-forest-labs/FLUX.1-dev",
|
28 |
torch_dtype=dtype,
|
29 |
token=huggingface_token
|
@@ -161,7 +161,7 @@ def enhance_image(image, text_prompt, seed, randomize_seed, width, height, guida
|
|
161 |
generator = torch.Generator(device=device).manual_seed(seed)
|
162 |
|
163 |
# Use tiled if large, else direct
|
164 |
-
if image.size[0] > MAX_IMAGE_SIZE or image.size[1] > MAX_IMAGE_SIZE:
|
165 |
output_image = tiled_flux_img2img(image, prompt, strength, num_inference_steps, guidance_scale)
|
166 |
else:
|
167 |
output_image = pipe(
|
@@ -169,10 +169,10 @@ def enhance_image(image, text_prompt, seed, randomize_seed, width, height, guida
|
|
169 |
image=image,
|
170 |
generator=generator,
|
171 |
num_inference_steps=num_inference_steps,
|
172 |
-
width=width,
|
173 |
-
height=height,
|
174 |
guidance_scale=guidance_scale,
|
175 |
-
strength=strength
|
176 |
).images[0]
|
177 |
return output_image, prompt, seed
|
178 |
|
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
6 |
+
from diffusers import FluxImg2ImgPipeline
|
7 |
import random
|
8 |
import numpy as np
|
9 |
import os
|
|
|
22 |
dtype = torch.bfloat16
|
23 |
huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
|
24 |
|
25 |
+
# Load FLUX img2img pipeline directly to avoid auto_pipeline issues
|
26 |
+
pipe = FluxImg2ImgPipeline.from_pretrained(
|
27 |
"black-forest-labs/FLUX.1-dev",
|
28 |
torch_dtype=dtype,
|
29 |
token=huggingface_token
|
|
|
161 |
generator = torch.Generator(device=device).manual_seed(seed)
|
162 |
|
163 |
# Use tiled if large, else direct
|
164 |
+
if image and (image.size[0] > MAX_IMAGE_SIZE or image.size[1] > MAX_IMAGE_SIZE):
|
165 |
output_image = tiled_flux_img2img(image, prompt, strength, num_inference_steps, guidance_scale)
|
166 |
else:
|
167 |
output_image = pipe(
|
|
|
169 |
image=image,
|
170 |
generator=generator,
|
171 |
num_inference_steps=num_inference_steps,
|
172 |
+
width=width if image is None else None,
|
173 |
+
height=height if image is None else None,
|
174 |
guidance_scale=guidance_scale,
|
175 |
+
strength=strength if image is not None else 1.0 # For text2img, strength=1.0
|
176 |
).images[0]
|
177 |
return output_image, prompt, seed
|
178 |
|