Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -69,16 +69,21 @@ def save_captions_to_csv(captions, csv_file_path='image_captions.csv'):
|
|
69 |
writer.writerows(captions)
|
70 |
return csv_file_path
|
71 |
|
72 |
-
def
|
73 |
captions = []
|
74 |
if zip_files:
|
75 |
zip_file_paths = [zip_file.name for zip_file in zip_files]
|
76 |
captions.extend(process_zip_files(zip_file_paths))
|
|
|
|
|
|
|
|
|
|
|
77 |
if image_files:
|
78 |
image_file_paths = [image_file.name for image_file in image_files]
|
79 |
captions.extend(process_images(image_file_paths))
|
80 |
|
81 |
-
return save_captions_to_csv(captions)
|
82 |
|
83 |
def combine_csv_files(file1, file2, output_file='combined_captions.csv'):
|
84 |
with open(output_file, mode='w', newline='') as outfile:
|
@@ -96,9 +101,9 @@ def combine_csv_files(file1, file2, output_file='combined_captions.csv'):
|
|
96 |
return output_file
|
97 |
|
98 |
def add_files(zip_files, image_files, new_zip_files, new_image_files):
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
|
103 |
css = '''
|
104 |
h1#title {
|
@@ -134,21 +139,20 @@ with demo:
|
|
134 |
with gr.Column(scale=1):
|
135 |
new_zip_files = gr.File(label="Upload Zip Files", type="filepath", file_count="multiple")
|
136 |
generate_zip_captions_btn = gr.Button("Generate Zip Captions")
|
137 |
-
output_zip_file = gr.File(label="Download Zip Captions")
|
138 |
with gr.Column(scale=1):
|
139 |
new_image_files = gr.File(label="Upload Images", type="filepath", file_count="multiple")
|
140 |
generate_image_captions_btn = gr.Button("Generate Image Captions")
|
141 |
-
output_image_file = gr.File(label="Download Image Captions")
|
142 |
-
|
143 |
-
add_files_btn = gr.Button("Add More Files")
|
144 |
-
combine_files_btn = gr.Button("Combine CSV Files")
|
145 |
-
combined_file = gr.File(label="Download Combined Captions")
|
146 |
|
|
|
|
|
|
|
|
|
147 |
|
148 |
-
|
149 |
add_files_btn.click(add_files, inputs=[zip_files, image_files, new_zip_files, new_image_files], outputs=[zip_files, image_files])
|
150 |
-
generate_zip_captions_btn.click(fn=
|
151 |
-
generate_image_captions_btn.click(fn=
|
152 |
combine_files_btn.click(fn=combine_csv_files, inputs=[output_zip_file, output_image_file], outputs=combined_file)
|
153 |
|
154 |
demo.launch(share=True)
|
|
|
69 |
writer.writerows(captions)
|
70 |
return csv_file_path
|
71 |
|
72 |
+
def gr_process_zip(zip_files):
|
73 |
captions = []
|
74 |
if zip_files:
|
75 |
zip_file_paths = [zip_file.name for zip_file in zip_files]
|
76 |
captions.extend(process_zip_files(zip_file_paths))
|
77 |
+
|
78 |
+
return save_captions_to_csv(captions, 'zip_image_captions.csv')
|
79 |
+
|
80 |
+
def gr_process_images(image_files):
|
81 |
+
captions = []
|
82 |
if image_files:
|
83 |
image_file_paths = [image_file.name for image_file in image_files]
|
84 |
captions.extend(process_images(image_file_paths))
|
85 |
|
86 |
+
return save_captions_to_csv(captions, 'image_captions.csv')
|
87 |
|
88 |
def combine_csv_files(file1, file2, output_file='combined_captions.csv'):
|
89 |
with open(output_file, mode='w', newline='') as outfile:
|
|
|
101 |
return output_file
|
102 |
|
103 |
def add_files(zip_files, image_files, new_zip_files, new_image_files):
|
104 |
+
zip_files += new_zip_files
|
105 |
+
image_files += new_image_files
|
106 |
+
return zip_files, image_files
|
107 |
|
108 |
css = '''
|
109 |
h1#title {
|
|
|
139 |
with gr.Column(scale=1):
|
140 |
new_zip_files = gr.File(label="Upload Zip Files", type="filepath", file_count="multiple")
|
141 |
generate_zip_captions_btn = gr.Button("Generate Zip Captions")
|
142 |
+
output_zip_file = gr.File(label="Download Zip Captions", interactive=False)
|
143 |
with gr.Column(scale=1):
|
144 |
new_image_files = gr.File(label="Upload Images", type="filepath", file_count="multiple")
|
145 |
generate_image_captions_btn = gr.Button("Generate Image Captions")
|
146 |
+
output_image_file = gr.File(label="Download Image Captions", interactive=False)
|
|
|
|
|
|
|
|
|
147 |
|
148 |
+
with gr.Row():
|
149 |
+
add_files_btn = gr.Button("Add More Files")
|
150 |
+
combine_files_btn = gr.Button("Combine CSV Files")
|
151 |
+
combined_file = gr.File(label="Download Combined Captions", interactive=False)
|
152 |
|
|
|
153 |
add_files_btn.click(add_files, inputs=[zip_files, image_files, new_zip_files, new_image_files], outputs=[zip_files, image_files])
|
154 |
+
generate_zip_captions_btn.click(fn=gr_process_zip, inputs=zip_files, outputs=output_zip_file)
|
155 |
+
generate_image_captions_btn.click(fn=gr_process_images, inputs=image_files, outputs=output_image_file)
|
156 |
combine_files_btn.click(fn=combine_csv_files, inputs=[output_zip_file, output_image_file], outputs=combined_file)
|
157 |
|
158 |
demo.launch(share=True)
|