Spaces:
Sleeping
Sleeping
Commit
·
e1c27aa
1
Parent(s):
de0c472
introduced gradio/app_iterative_file_upload.py
Browse files
gradio/app_iterative_file_upload.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def upload_files(files, filepaths):
|
| 4 |
+
verbose = False
|
| 5 |
+
filepaths_new = [file.name for file in files]
|
| 6 |
+
if verbose:
|
| 7 |
+
print(f'previous files: {filepaths}')
|
| 8 |
+
print(f'new files: {filepaths_new}')
|
| 9 |
+
filepaths = filepaths + filepaths_new
|
| 10 |
+
return filepaths, filepaths
|
| 11 |
+
|
| 12 |
+
with gr.Blocks() as demo:
|
| 13 |
+
gr.Markdown("Define References")
|
| 14 |
+
filepaths = gr.State([])
|
| 15 |
+
file_output = gr.File()
|
| 16 |
+
upload_button = gr.UploadButton("Upload PDF(s)", file_count="multiple")
|
| 17 |
+
upload_button.upload(
|
| 18 |
+
fn=upload_files,
|
| 19 |
+
inputs=[upload_button, filepaths],
|
| 20 |
+
outputs=[file_output, filepaths])
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
demo.launch()
|