Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,21 +69,15 @@ 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 |
-
|
| 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 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
def combine_csv_files(file1, file2, output_file='combined_captions.csv'):
|
| 89 |
with open(output_file, mode='w', newline='') as outfile:
|
|
@@ -151,8 +145,8 @@ with demo:
|
|
| 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=
|
| 155 |
-
generate_image_captions_btn.click(fn=
|
| 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)
|
|
|
|
| 69 |
writer.writerows(captions)
|
| 70 |
return csv_file_path
|
| 71 |
|
| 72 |
+
def gr_process(zip_files, image_files):
|
|
|
|
| 73 |
if zip_files:
|
| 74 |
zip_file_paths = [zip_file.name for zip_file in zip_files]
|
| 75 |
+
return process_zip_files(zip_file_paths)
|
| 76 |
+
elif image_files:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
image_file_paths = [image_file.name for image_file in image_files]
|
| 78 |
+
return process_images(image_file_paths)
|
| 79 |
+
else:
|
| 80 |
+
return None
|
| 81 |
|
| 82 |
def combine_csv_files(file1, file2, output_file='combined_captions.csv'):
|
| 83 |
with open(output_file, mode='w', newline='') as outfile:
|
|
|
|
| 145 |
combined_file = gr.File(label="Download Combined Captions", interactive=False)
|
| 146 |
|
| 147 |
add_files_btn.click(add_files, inputs=[zip_files, image_files, new_zip_files, new_image_files], outputs=[zip_files, image_files])
|
| 148 |
+
generate_zip_captions_btn.click(fn=gr_process, inputs=zip_files, outputs=output_zip_file)
|
| 149 |
+
generate_image_captions_btn.click(fn=gr_process, inputs=image_files, outputs=output_image_file)
|
| 150 |
combine_files_btn.click(fn=combine_csv_files, inputs=[output_zip_file, output_image_file], outputs=combined_file)
|
| 151 |
|
| 152 |
demo.launch(share=True)
|