Spaces:
Build error
Build error
Commit
·
e981e7f
1
Parent(s):
8f5362f
download csv?
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from lavis.processors import load_processor
|
|
7 |
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoProcessor
|
8 |
import tensorflow as tf
|
9 |
import tensorflow_hub as hub
|
|
|
10 |
from sklearn.metrics.pairwise import cosine_similarity
|
11 |
|
12 |
|
@@ -120,21 +121,24 @@ def process_images_and_statements(image):
|
|
120 |
logging.info('Finished process_images_and_statements')
|
121 |
|
122 |
# Return the DataFrame directly as output (no need to convert to HTML)
|
123 |
-
|
|
|
|
|
|
|
|
|
124 |
|
125 |
# Gradio interface
|
126 |
image_input = gr.inputs.Image()
|
127 |
-
|
|
|
128 |
|
129 |
iface = gr.Interface(
|
130 |
fn=process_images_and_statements,
|
131 |
inputs=image_input,
|
132 |
-
outputs=
|
133 |
title="Image Captioning and Image-Text Matching",
|
134 |
theme='sudeepshouche/minimalist',
|
135 |
css=".output { flex-direction: column; } .output .outputs { width: 100%; }" # Custom CSS
|
136 |
)
|
137 |
|
138 |
-
iface.launch()
|
139 |
-
|
140 |
-
|
|
|
7 |
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoProcessor
|
8 |
import tensorflow as tf
|
9 |
import tensorflow_hub as hub
|
10 |
+
import io
|
11 |
from sklearn.metrics.pairwise import cosine_similarity
|
12 |
|
13 |
|
|
|
121 |
logging.info('Finished process_images_and_statements')
|
122 |
|
123 |
# Return the DataFrame directly as output (no need to convert to HTML)
|
124 |
+
# Save results_df to a CSV file
|
125 |
+
csv_results = save_dataframe_to_csv(results_df)
|
126 |
+
|
127 |
+
# Return both the DataFrame and the CSV data for the Gradio interface
|
128 |
+
return results_df, csv_results # <--- Return results_df and csv_results
|
129 |
|
130 |
# Gradio interface
|
131 |
image_input = gr.inputs.Image()
|
132 |
+
output_df = gr.outputs.Dataframe(type="pandas", label="Results") # <--- Use "pandas" type for DataFrame output
|
133 |
+
output_csv = gr.outputs.File(label="Download CSV") # <--- Added a new output for the downloadable CSV file
|
134 |
|
135 |
iface = gr.Interface(
|
136 |
fn=process_images_and_statements,
|
137 |
inputs=image_input,
|
138 |
+
outputs=[output_df, output_csv], # <--- Updated outputs to include output_csv
|
139 |
title="Image Captioning and Image-Text Matching",
|
140 |
theme='sudeepshouche/minimalist',
|
141 |
css=".output { flex-direction: column; } .output .outputs { width: 100%; }" # Custom CSS
|
142 |
)
|
143 |
|
144 |
+
iface.launch()
|
|
|
|