Spaces:
Build error
Build error
Commit
·
968f9cc
1
Parent(s):
7ecd689
trying to add csv shit again
Browse files
app.py
CHANGED
@@ -74,7 +74,7 @@ def save_dataframe_to_csv(df):
|
|
74 |
return temp_file_path
|
75 |
|
76 |
# Main function to perform image captioning and image-text matching
|
77 |
-
def process_images_and_statements(image):
|
78 |
logging.info('Starting process_images_and_statements')
|
79 |
|
80 |
# Generate image caption for the uploaded image using git-large-r-textcaps
|
@@ -101,11 +101,12 @@ def process_images_and_statements(image):
|
|
101 |
|
102 |
# Append the result to the results_list
|
103 |
results_list.append({
|
|
|
104 |
'Statement': statement,
|
105 |
-
'Generated Caption': caption,
|
106 |
-
'Textual Similarity Score': f"{textual_similarity_score:.2f}%",
|
107 |
-
'ITM Score': f"{itm_score_statement:.2f}%",
|
108 |
-
'Final Combined Score': f"{final_score:.2f}%"
|
109 |
})
|
110 |
|
111 |
# Convert the results_list to a DataFrame using pandas.concat
|
@@ -117,17 +118,17 @@ def process_images_and_statements(image):
|
|
117 |
csv_results = save_dataframe_to_csv(results_df)
|
118 |
|
119 |
# Return both the DataFrame and the CSV data for the Gradio interface
|
120 |
-
return results_df, csv_results
|
121 |
|
122 |
# Gradio interface
|
123 |
-
image_input = gr.inputs.Image()
|
124 |
output_df = gr.outputs.Dataframe(type="pandas", label="Results")
|
125 |
output_csv = gr.outputs.File(label="Download CSV")
|
126 |
|
127 |
iface = gr.Interface(
|
128 |
fn=process_images_and_statements,
|
129 |
-
inputs=image_input,
|
130 |
-
outputs=[output_df, output_csv],
|
131 |
title="Image Captioning and Image-Text Matching",
|
132 |
theme='sudeepshouche/minimalist',
|
133 |
css=".output { flex-direction: column; } .output .outputs { width: 100%; }" # Custom CSS
|
|
|
74 |
return temp_file_path
|
75 |
|
76 |
# Main function to perform image captioning and image-text matching
|
77 |
+
def process_images_and_statements(image, file):
|
78 |
logging.info('Starting process_images_and_statements')
|
79 |
|
80 |
# Generate image caption for the uploaded image using git-large-r-textcaps
|
|
|
101 |
|
102 |
# Append the result to the results_list
|
103 |
results_list.append({
|
104 |
+
'File Name': file.name, # Include the file name
|
105 |
'Statement': statement,
|
106 |
+
'Generated Caption': caption,
|
107 |
+
'Textual Similarity Score': f"{textual_similarity_score:.2f}%",
|
108 |
+
'ITM Score': f"{itm_score_statement:.2f}%",
|
109 |
+
'Final Combined Score': f"{final_score:.2f}%"
|
110 |
})
|
111 |
|
112 |
# Convert the results_list to a DataFrame using pandas.concat
|
|
|
118 |
csv_results = save_dataframe_to_csv(results_df)
|
119 |
|
120 |
# Return both the DataFrame and the CSV data for the Gradio interface
|
121 |
+
return results_df, csv_results
|
122 |
|
123 |
# Gradio interface
|
124 |
+
image_input = gr.inputs.Image(type="file", label="Upload Image")
|
125 |
output_df = gr.outputs.Dataframe(type="pandas", label="Results")
|
126 |
output_csv = gr.outputs.File(label="Download CSV")
|
127 |
|
128 |
iface = gr.Interface(
|
129 |
fn=process_images_and_statements,
|
130 |
+
inputs=[image_input],
|
131 |
+
outputs=[output_df, output_csv],
|
132 |
title="Image Captioning and Image-Text Matching",
|
133 |
theme='sudeepshouche/minimalist',
|
134 |
css=".output { flex-direction: column; } .output .outputs { width: 100%; }" # Custom CSS
|