linoyts HF Staff commited on
Commit
68c0221
·
verified ·
1 Parent(s): 2f6d0cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -18
app.py CHANGED
@@ -8,10 +8,8 @@ from PIL import Image
8
  from diffusers import StableDiffusionXLPipeline
9
  import open_clip
10
  from huggingface_hub import hf_hub_download
11
- from IP_Adapter.ip_adapter import IPAdapterXL
12
- from perform_swap import compute_dataset_embeds_svd, get_modified_images_embeds_composition
13
- import tempfile
14
- import uuid
15
 
16
  device = "cuda" if torch.cuda.is_available() else "cpu"
17
 
@@ -41,14 +39,6 @@ def get_image_embeds(pil_image, model=clip_model, preproc=preprocess, dev=device
41
  embeds = model.encode_image(image.to(dev))
42
  return embeds.cpu().detach().numpy()
43
 
44
- def save_temp_image(image):
45
- """Save a PIL image to a temporary file and return the path"""
46
- temp_dir = tempfile.gettempdir()
47
- filename = f"{uuid.uuid4()}.png"
48
- filepath = os.path.join(temp_dir, filename)
49
- image.save(filepath)
50
- return filepath
51
-
52
  def process_images(
53
  base_image,
54
  concept_image1, concept_desc1,
@@ -159,8 +149,8 @@ def process_and_display(
159
  return modified_images
160
 
161
  with gr.Blocks(title="Image Concept Composition") as demo:
162
- gr.Markdown("# Image Concept Composition")
163
- gr.Markdown("Upload a base image and 1-3 concept images to create new images that combine these concepts.")
164
 
165
  with gr.Row():
166
  with gr.Column():
@@ -193,11 +183,10 @@ with gr.Blocks(title="Image Concept Composition") as demo:
193
  scale = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Scale")
194
  seed = gr.Number(value=420, label="Seed", precision=0)
195
 
196
- submit_btn = gr.Button("Generate Image")
197
 
198
  with gr.Column():
199
- gallery = gr.Gallery(label="Generated Image", show_label=True)
200
- status = gr.Markdown("Upload images and click Generate")
201
 
202
  submit_btn.click(
203
  fn=process_and_display,
@@ -209,7 +198,7 @@ with gr.Blocks(title="Image Concept Composition") as demo:
209
  rank1, rank2, rank3,
210
  prompt, scale, seed
211
  ],
212
- outputs=[gallery, status]
213
  )
214
 
215
 
 
8
  from diffusers import StableDiffusionXLPipeline
9
  import open_clip
10
  from huggingface_hub import hf_hub_download
11
+ from IP_Composer.IP_Adapter.ip_adapter import IPAdapterXL
12
+ from IP_Composer.perform_swap import compute_dataset_embeds_svd, get_modified_images_embeds_composition
 
 
13
 
14
  device = "cuda" if torch.cuda.is_available() else "cpu"
15
 
 
39
  embeds = model.encode_image(image.to(dev))
40
  return embeds.cpu().detach().numpy()
41
 
 
 
 
 
 
 
 
 
42
  def process_images(
43
  base_image,
44
  concept_image1, concept_desc1,
 
149
  return modified_images
150
 
151
  with gr.Blocks(title="Image Concept Composition") as demo:
152
+ gr.Markdown("# IP Composer")
153
+ gr.Markdown("")
154
 
155
  with gr.Row():
156
  with gr.Column():
 
183
  scale = gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Scale")
184
  seed = gr.Number(value=420, label="Seed", precision=0)
185
 
186
+ submit_btn = gr.Button("Generate")
187
 
188
  with gr.Column():
189
+ output_image = gr.Image(label="composed output", show_label=True)
 
190
 
191
  submit_btn.click(
192
  fn=process_and_display,
 
198
  rank1, rank2, rank3,
199
  prompt, scale, seed
200
  ],
201
+ outputs=[output_image]
202
  )
203
 
204