DamarJati commited on
Commit
c56b69c
1 Parent(s): 9d0afe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -7,10 +7,10 @@ from einops import rearrange
7
  import requests
8
  import spaces
9
  from huggingface_hub import login
 
10
 
11
- hf_token = os.getenv("HF_TOKEN")
12
  # Login to Hugging Face
13
- login(token=hf_token)
14
 
15
  from image_datasets.canny_dataset import canny_processor, c_crop
16
  from src.flux.sampling import denoise_controlnet, get_noise, get_schedule, prepare, unpack
@@ -51,7 +51,7 @@ def preprocess_canny_image(image, width=1024, height=1024):
51
  image = canny_processor(image)
52
  return image
53
 
54
- @spaces.GPU()
55
  def generate_image(prompt, control_image, num_steps=50, guidance=4, width=512, height=512, seed=42, random_seed=False):
56
  if random_seed:
57
  seed = np.random.randint(0, 10000)
@@ -89,7 +89,7 @@ def generate_image(prompt, control_image, num_steps=50, guidance=4, width=512, h
89
  x1 = rearrange(x1[-1], "c h w -> h w c")
90
  output_img = Image.fromarray((127.5 * (x1 + 1.0)).cpu().byte().numpy())
91
 
92
- return output_img
93
 
94
  interface = gr.Interface(
95
  fn=generate_image,
@@ -103,7 +103,7 @@ interface = gr.Interface(
103
  gr.Number(value=42, label="Seed"),
104
  gr.Checkbox(label="Random Seed")
105
  ],
106
- outputs=gr.Image(type="pil", label="Generated Image"),
107
  title="FLUX.1 Controlnet Cany",
108
  description="Generate images using ControlNet and a text prompt.\n[[non-commercial license, Flux.1 Dev](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)]"
109
  )
 
7
  import requests
8
  import spaces
9
  from huggingface_hub import login
10
+ from gradio_imageslider import ImageSlider # Import ImageSlider
11
 
 
12
  # Login to Hugging Face
13
+ login(token=os.getenv("HF_TOKEN"))
14
 
15
  from image_datasets.canny_dataset import canny_processor, c_crop
16
  from src.flux.sampling import denoise_controlnet, get_noise, get_schedule, prepare, unpack
 
51
  image = canny_processor(image)
52
  return image
53
 
54
+ @spaces.GPU(duration=120)
55
  def generate_image(prompt, control_image, num_steps=50, guidance=4, width=512, height=512, seed=42, random_seed=False):
56
  if random_seed:
57
  seed = np.random.randint(0, 10000)
 
89
  x1 = rearrange(x1[-1], "c h w -> h w c")
90
  output_img = Image.fromarray((127.5 * (x1 + 1.0)).cpu().byte().numpy())
91
 
92
+ return [control_image, output_img] # Return both images for slider
93
 
94
  interface = gr.Interface(
95
  fn=generate_image,
 
103
  gr.Number(value=42, label="Seed"),
104
  gr.Checkbox(label="Random Seed")
105
  ],
106
+ outputs=ImageSlider(label="Before / After"), # Use ImageSlider as the output
107
  title="FLUX.1 Controlnet Cany",
108
  description="Generate images using ControlNet and a text prompt.\n[[non-commercial license, Flux.1 Dev](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)]"
109
  )