Spaces:
Build error
Build error
brianjking
commited on
Commit
•
5c5800a
1
Parent(s):
8510f91
bring up to date
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ import tensorflow as tf
|
|
9 |
import tensorflow_hub as hub
|
10 |
from sklearn.metrics.pairwise import cosine_similarity
|
11 |
|
|
|
12 |
# Import logging module
|
13 |
import logging
|
14 |
|
@@ -87,13 +88,13 @@ def process_images_and_statements(image):
|
|
87 |
# Generate image caption for the uploaded image using git-large-r-textcaps
|
88 |
caption = generate_caption(git_processor_large_textcaps, git_model_large_textcaps, image)
|
89 |
|
90 |
-
# Initialize an empty list to store the results
|
91 |
-
results = []
|
92 |
-
|
93 |
# Define weights for combining textual similarity score and image-statement ITM score (adjust as needed)
|
94 |
weight_textual_similarity = 0.5
|
95 |
weight_statement = 0.5
|
96 |
|
|
|
|
|
|
|
97 |
# Loop through each predefined statement
|
98 |
for statement in statements:
|
99 |
# Compute textual similarity between caption and statement
|
@@ -105,21 +106,30 @@ def process_images_and_statements(image):
|
|
105 |
# Combine the two scores using a weighted average
|
106 |
final_score = (weight_textual_similarity * textual_similarity_score) + (weight_statement * itm_score_statement)
|
107 |
|
108 |
-
#
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
113 |
|
114 |
logging.info('Finished process_images_and_statements')
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
return output
|
119 |
|
120 |
# Gradio interface
|
121 |
image_input = gr.inputs.Image()
|
122 |
-
output = gr.outputs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
-
iface = gr.Interface(fn=process_images_and_statements, inputs=image_input, outputs=output, title="Image Captioning and Image-Text Matching")
|
125 |
iface.launch()
|
|
|
9 |
import tensorflow_hub as hub
|
10 |
from sklearn.metrics.pairwise import cosine_similarity
|
11 |
|
12 |
+
|
13 |
# Import logging module
|
14 |
import logging
|
15 |
|
|
|
88 |
# Generate image caption for the uploaded image using git-large-r-textcaps
|
89 |
caption = generate_caption(git_processor_large_textcaps, git_model_large_textcaps, image)
|
90 |
|
|
|
|
|
|
|
91 |
# Define weights for combining textual similarity score and image-statement ITM score (adjust as needed)
|
92 |
weight_textual_similarity = 0.5
|
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
|
|
|
106 |
# Combine the two scores using a weighted average
|
107 |
final_score = (weight_textual_similarity * textual_similarity_score) + (weight_statement * itm_score_statement)
|
108 |
|
109 |
+
# Append the result to the DataFrame
|
110 |
+
results_df = results_df.append({
|
111 |
+
'Statement': statement,
|
112 |
+
'Textual Similarity Score': textual_similarity_score,
|
113 |
+
'ITM Score': itm_score_statement,
|
114 |
+
'Final Combined Score': final_score
|
115 |
+
}, ignore_index=True)
|
116 |
|
117 |
logging.info('Finished process_images_and_statements')
|
118 |
|
119 |
+
# Return the DataFrame directly as output (no need to convert to HTML)
|
120 |
+
return results_df # <--- Return results_df directly
|
|
|
121 |
|
122 |
# Gradio interface
|
123 |
image_input = gr.inputs.Image()
|
124 |
+
output = gr.outputs.Dataframe(type="pandas", label="Results") # <--- Use "pandas" type for DataFrame output
|
125 |
+
|
126 |
+
iface = gr.Interface(
|
127 |
+
fn=process_images_and_statements,
|
128 |
+
inputs=image_input,
|
129 |
+
outputs=output,
|
130 |
+
title="Image Captioning and Image-Text Matching",
|
131 |
+
theme='freddyaboulton/dracula_revamped',
|
132 |
+
css=".output { flex-direction: column; } .output .outputs { width: 100%; }" # Custom CSS
|
133 |
+
)
|
134 |
|
|
|
135 |
iface.launch()
|