Spaces:
Build error
Build error
Commit
·
d7bec20
1
Parent(s):
1107d28
get rid of dataframe as it was hugely broken
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ import tensorflow as tf
|
|
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,13 +87,13 @@ def process_images_and_statements(image):
|
|
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,18 +105,16 @@ def process_images_and_statements(image):
|
|
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 |
-
#
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
'Final Combined Score': final_score
|
115 |
-
}, ignore_index=True)
|
116 |
|
117 |
logging.info('Finished process_images_and_statements')
|
118 |
|
119 |
-
|
120 |
-
output =
|
121 |
return output
|
122 |
|
123 |
# Gradio interface
|
@@ -125,4 +122,4 @@ image_input = gr.inputs.Image()
|
|
125 |
output = gr.outputs.Textbox(label="Results")
|
126 |
|
127 |
iface = gr.Interface(fn=process_images_and_statements, inputs=image_input, outputs=output, title="Image Captioning and Image-Text Matching")
|
128 |
-
iface.launch()
|
|
|
9 |
import tensorflow_hub as hub
|
10 |
from sklearn.metrics.pairwise import cosine_similarity
|
11 |
|
|
|
12 |
# Import logging module
|
13 |
import logging
|
14 |
|
|
|
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 |
# Combine the two scores using a weighted average
|
106 |
final_score = (weight_textual_similarity * textual_similarity_score) + (weight_statement * itm_score_statement)
|
107 |
|
108 |
+
# Store the result
|
109 |
+
result_text = (f'Textual similarity between caption ("{caption}") and statement ("{statement}") is {textual_similarity_score:.3f}\n'
|
110 |
+
f'The image-statement pair ("{statement}") is matched with a probability of {itm_score_statement:.3%}\n'
|
111 |
+
f'The final combined score is {final_score:.3%}')
|
112 |
+
results.append(result_text)
|
|
|
|
|
113 |
|
114 |
logging.info('Finished process_images_and_statements')
|
115 |
|
116 |
+
# Combine the results and return them
|
117 |
+
output = "\n\n".join(results)
|
118 |
return output
|
119 |
|
120 |
# Gradio interface
|
|
|
122 |
output = gr.outputs.Textbox(label="Results")
|
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()
|