Spaces:
Runtime error
Runtime error
Commit
·
17fbc96
1
Parent(s):
8233dd1
Update app.py
Browse files
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(
|
47 |
-
|
48 |
-
inputs = tokenizer_caption(
|
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(
|
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
|
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
|
|
|
|
|
|