Linoy Tsaban commited on
Commit
da5eff7
1 Parent(s): 5c86655

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -9
app.py CHANGED
@@ -26,15 +26,13 @@ blip_model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image
26
 
27
  ## IMAGE CPATIONING ##
28
  def caption_image(input_image):
29
-
30
- if not input_image is None:
31
  inputs = blip_processor(images=input_image, return_tensors="pt").to(device)
32
  pixel_values = inputs.pixel_values
33
-
34
  generated_ids = blip_model.generate(pixel_values=pixel_values, max_length=50)
35
  generated_caption = blip_processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
36
  return generated_caption
37
- return ""
38
 
39
 
40
  ## DDPM INVERSION AND SAMPLING ##
@@ -363,10 +361,7 @@ with gr.Blocks(css="style.css") as demo:
363
 
364
 
365
  def reset_do_inversion():
366
- if not input_image is None:
367
- return True
368
- else:
369
- return False
370
 
371
  def reset_do_reconstruction():
372
  do_reconstruction = True
@@ -599,7 +594,7 @@ with gr.Blocks(css="style.css") as demo:
599
 
600
 
601
  # Automatically start inverting upon input_image change
602
- input_image.change(
603
  fn = reset_do_inversion,
604
  inputs = [input_image],
605
  outputs = [do_inversion],
 
26
 
27
  ## IMAGE CPATIONING ##
28
  def caption_image(input_image):
 
 
29
  inputs = blip_processor(images=input_image, return_tensors="pt").to(device)
30
  pixel_values = inputs.pixel_values
31
+
32
  generated_ids = blip_model.generate(pixel_values=pixel_values, max_length=50)
33
  generated_caption = blip_processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
34
  return generated_caption
35
+
36
 
37
 
38
  ## DDPM INVERSION AND SAMPLING ##
 
361
 
362
 
363
  def reset_do_inversion():
364
+ return True
 
 
 
365
 
366
  def reset_do_reconstruction():
367
  do_reconstruction = True
 
594
 
595
 
596
  # Automatically start inverting upon input_image change
597
+ input_image.upload(
598
  fn = reset_do_inversion,
599
  inputs = [input_image],
600
  outputs = [do_inversion],