iamrobotbear commited on
Commit
17fbc96
·
1 Parent(s): 8233dd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -43,17 +43,17 @@ def compute_itm_scores(image):
43
  return output
44
 
45
  # Function to generate image captions using TextCaps
46
- def generate_image_captions(image):
47
- pil_image = Image.fromarray(image.astype('uint8'), 'RGB')
48
- inputs = tokenizer_caption(pil_image, return_tensors="pt", padding=True, truncation=True)
49
  outputs = model_caption.generate(**inputs)
50
- caption = tokenizer_caption.decode(outputs[0])
51
- return caption
52
 
53
  # Main function to perform image captioning and image-text matching
54
  def process_images_and_statements(image):
55
  # Generate image captions using TextCaps
56
- captions = generate_image_captions(image)
57
 
58
  # Compute ITM scores for predefined statements using LAVIS
59
  itm_scores = compute_itm_scores(image)
@@ -64,7 +64,4 @@ def process_images_and_statements(image):
64
 
65
  # Gradio interface
66
  image_input = gr.inputs.Image()
67
- output = gr.outputs.Textbox(label="Results")
68
-
69
- iface = gr.Interface(fn=process_images_and_statements, inputs=image_input, outputs=output, title="Image Captioning and Image-Text Matching")
70
- iface.launch()
 
43
  return output
44
 
45
  # Function to generate image captions using TextCaps
46
+ def generate_image_captions():
47
+ prompt = "A photo of"
48
+ inputs = tokenizer_caption(prompt, return_tensors="pt", padding=True, truncation=True)
49
  outputs = model_caption.generate(**inputs)
50
+ caption = tokenizer_caption.decode(outputs[0], skip_special_tokens=True)
51
+ return prompt + " " + caption
52
 
53
  # Main function to perform image captioning and image-text matching
54
  def process_images_and_statements(image):
55
  # Generate image captions using TextCaps
56
+ captions = generate_image_captions()
57
 
58
  # Compute ITM scores for predefined statements using LAVIS
59
  itm_scores = compute_itm_scores(image)
 
64
 
65
  # Gradio interface
66
  image_input = gr.inputs.Image()
67
+ output = gr.outputs.Textbox(label