Spaces:
Build error
Build error
iamrobotbear
commited on
Commit
·
8f5362f
1
Parent(s):
e17785f
add generated captions to the dataframe
Browse files
app.py
CHANGED
@@ -93,29 +93,30 @@ def process_images_and_statements(image):
|
|
93 |
weight_statement = 0.5
|
94 |
|
95 |
# Initialize an empty DataFrame with column names
|
96 |
-
results_df = pd.DataFrame(columns=['Statement', 'Textual Similarity Score', 'ITM Score', 'Final Combined Score'])
|
97 |
|
98 |
# Loop through each predefined statement
|
99 |
for statement in statements:
|
100 |
# Compute textual similarity between caption and statement
|
101 |
-
textual_similarity_score = compute_textual_similarity(caption, statement)
|
102 |
|
103 |
# Compute ITM score for the image-statement pair
|
104 |
-
itm_score_statement = compute_itm_score(image, statement)
|
105 |
|
106 |
# Combine the two scores using a weighted average
|
107 |
-
#final_score = (weight_textual_similarity * textual_similarity_score) + (weight_statement * itm_score_statement)
|
108 |
final_score = ((weight_textual_similarity * textual_similarity_score) +
|
109 |
-
(weight_statement * itm_score_statement))
|
110 |
|
111 |
-
# Append the result to the DataFrame
|
112 |
results_df = results_df.append({
|
113 |
'Statement': statement,
|
114 |
-
'
|
115 |
-
'
|
116 |
-
'
|
|
|
117 |
}, ignore_index=True)
|
118 |
|
|
|
119 |
logging.info('Finished process_images_and_statements')
|
120 |
|
121 |
# Return the DataFrame directly as output (no need to convert to HTML)
|
@@ -134,4 +135,6 @@ iface = gr.Interface(
|
|
134 |
css=".output { flex-direction: column; } .output .outputs { width: 100%; }" # Custom CSS
|
135 |
)
|
136 |
|
137 |
-
iface.launch()
|
|
|
|
|
|
93 |
weight_statement = 0.5
|
94 |
|
95 |
# Initialize an empty DataFrame with column names
|
96 |
+
results_df = pd.DataFrame(columns=['Statement', 'Generated Caption', 'Textual Similarity Score', 'ITM Score', 'Final Combined Score'])
|
97 |
|
98 |
# Loop through each predefined statement
|
99 |
for statement in statements:
|
100 |
# Compute textual similarity between caption and statement
|
101 |
+
textual_similarity_score = (compute_textual_similarity(caption, statement) * 100) # Multiply by 100
|
102 |
|
103 |
# Compute ITM score for the image-statement pair
|
104 |
+
itm_score_statement = (compute_itm_score(image, statement) * 100) # Multiply by 100
|
105 |
|
106 |
# Combine the two scores using a weighted average
|
|
|
107 |
final_score = ((weight_textual_similarity * textual_similarity_score) +
|
108 |
+
(weight_statement * itm_score_statement))
|
109 |
|
110 |
+
# Append the result to the DataFrame with formatted percentage values
|
111 |
results_df = results_df.append({
|
112 |
'Statement': statement,
|
113 |
+
'Generated Caption': caption, # Include the generated caption
|
114 |
+
'Textual Similarity Score': f"{textual_similarity_score:.2f}%", # Format as percentage with two decimal places
|
115 |
+
'ITM Score': f"{itm_score_statement:.2f}%", # Format as percentage with two decimal places
|
116 |
+
'Final Combined Score': f"{final_score:.2f}%" # Format as percentage with two decimal places
|
117 |
}, ignore_index=True)
|
118 |
|
119 |
+
logging.info
|
120 |
logging.info('Finished process_images_and_statements')
|
121 |
|
122 |
# Return the DataFrame directly as output (no need to convert to HTML)
|
|
|
135 |
css=".output { flex-direction: column; } .output .outputs { width: 100%; }" # Custom CSS
|
136 |
)
|
137 |
|
138 |
+
iface.launch()
|
139 |
+
|
140 |
+
|