Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,17 +72,16 @@ def save_captions_to_csv(captions, csv_file_path='image_captions.csv'):
|
|
| 72 |
print("No captions to save.")
|
| 73 |
return csv_file_path
|
| 74 |
|
| 75 |
-
def
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
return save_captions_to_csv(captions, 'image_captions.csv')
|
| 86 |
|
| 87 |
def combine_csv_files(file1, file2, output_file='combined_captions.csv'):
|
| 88 |
with open(output_file, mode='w', newline='') as outfile:
|
|
@@ -149,8 +148,8 @@ with demo:
|
|
| 149 |
return zip_files, image_files
|
| 150 |
|
| 151 |
add_files_btn.click(add_files, inputs=[zip_files, image_files, new_zip_files, new_image_files], outputs=[zip_files, image_files])
|
| 152 |
-
generate_zip_captions_btn.click(fn=
|
| 153 |
-
generate_image_captions_btn.click(fn=
|
| 154 |
combine_files_btn.click(fn=combine_csv_files, inputs=[output_zip_file, output_image_file], outputs=combined_file)
|
| 155 |
|
| 156 |
demo.launch(share=True)
|
|
|
|
| 72 |
print("No captions to save.")
|
| 73 |
return csv_file_path
|
| 74 |
|
| 75 |
+
def gr_process(zip_files, image_files):
|
| 76 |
+
captions = []
|
| 77 |
+
if zip_files:
|
| 78 |
+
zip_file_paths = [zip_file.name for zip_file in zip_files]
|
| 79 |
+
captions.extend(process_zip_files(zip_file_paths))
|
| 80 |
+
if image_files:
|
| 81 |
+
image_file_paths = [image_file.name for image_file in image_files]
|
| 82 |
+
captions.extend(process_images(image_file_paths))
|
| 83 |
+
|
| 84 |
+
return save_captions_to_csv(captions)
|
|
|
|
| 85 |
|
| 86 |
def combine_csv_files(file1, file2, output_file='combined_captions.csv'):
|
| 87 |
with open(output_file, mode='w', newline='') as outfile:
|
|
|
|
| 148 |
return zip_files, image_files
|
| 149 |
|
| 150 |
add_files_btn.click(add_files, inputs=[zip_files, image_files, new_zip_files, new_image_files], outputs=[zip_files, image_files])
|
| 151 |
+
generate_zip_captions_btn.click(fn=gr_process, inputs=zip_files, outputs=output_zip_file)
|
| 152 |
+
generate_image_captions_btn.click(fn=gr_process, inputs=image_files, outputs=output_image_file)
|
| 153 |
combine_files_btn.click(fn=combine_csv_files, inputs=[output_zip_file, output_image_file], outputs=combined_file)
|
| 154 |
|
| 155 |
demo.launch(share=True)
|