Deva
commited on
Commit
·
ed96d64
1
Parent(s):
4073e83
Feature upload a whole folder
Browse files
app.py
CHANGED
@@ -4,7 +4,75 @@ import pandas as pd
|
|
4 |
import os
|
5 |
from tkinter import Tk, filedialog
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def display_name_files(_folder_path):
|
9 |
return f"{[img_name for img_name in os.listdir(_folder_path)]} \n"
|
10 |
|
@@ -58,7 +126,7 @@ def main():
|
|
58 |
|
59 |
demo = main()
|
60 |
demo.launch(inbrowser=True)
|
61 |
-
|
62 |
|
63 |
'''
|
64 |
def get_image_name(_image):
|
|
|
4 |
import os
|
5 |
from tkinter import Tk, filedialog
|
6 |
|
7 |
+
import gradio as gr
|
8 |
+
from pathlib import Path
|
9 |
+
|
10 |
+
|
11 |
+
def upload_file(files):
|
12 |
+
file_paths = [file.name for file in files]
|
13 |
+
return file_paths
|
14 |
+
|
15 |
+
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
upload_button = gr.UploadButton(
|
18 |
+
"Click to Upload a File", file_types=["image", "video"], file_count="multiple"
|
19 |
+
)
|
20 |
+
file_output = gr.File()
|
21 |
+
upload_button.upload(upload_file, upload_button, file_output)
|
22 |
+
|
23 |
+
demo.launch()
|
24 |
+
|
25 |
+
|
26 |
+
"""
|
27 |
+
current_file_path = Path(__file__).resolve()
|
28 |
+
relative_path = "path/to/file"
|
29 |
+
absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve()
|
30 |
+
|
31 |
|
32 |
+
def get_file_content(file):
|
33 |
+
return (file,)
|
34 |
+
|
35 |
+
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`')
|
38 |
+
submit_btn = gr.Button("Select")
|
39 |
+
with gr.Row():
|
40 |
+
file = gr.FileExplorer(
|
41 |
+
glob="**/components/*.py",
|
42 |
+
# value=["themes/utils"],
|
43 |
+
root_dir=absolute_path,
|
44 |
+
ignore_glob="**/__init__.py",
|
45 |
+
)
|
46 |
+
|
47 |
+
file2 = gr.FileExplorer(
|
48 |
+
glob="**/components/**/*.py",
|
49 |
+
root_dir=absolute_path,
|
50 |
+
ignore_glob="**/__init__.py",
|
51 |
+
)
|
52 |
+
submit_btn.click(lambda x: x, file, file2)
|
53 |
+
|
54 |
+
gr.Markdown("---")
|
55 |
+
gr.Markdown('### `FileExplorer` to `Code` -- `file_count="single"`')
|
56 |
+
with gr.Group():
|
57 |
+
with gr.Row():
|
58 |
+
file_3 = gr.FileExplorer(
|
59 |
+
scale=1,
|
60 |
+
glob="**/components/**/*.py",
|
61 |
+
value=["themes/utils"],
|
62 |
+
file_count="single",
|
63 |
+
root_dir=absolute_path,
|
64 |
+
ignore_glob="**/__init__.py",
|
65 |
+
elem_id="file",
|
66 |
+
)
|
67 |
+
|
68 |
+
code = gr.Code(lines=30, scale=2, language="python")
|
69 |
+
|
70 |
+
file_3.change(get_file_content, file_3, code)
|
71 |
+
|
72 |
+
if __name__ == "__main__":
|
73 |
+
demo.launch()
|
74 |
+
"""
|
75 |
+
""" Version 1
|
76 |
def display_name_files(_folder_path):
|
77 |
return f"{[img_name for img_name in os.listdir(_folder_path)]} \n"
|
78 |
|
|
|
126 |
|
127 |
demo = main()
|
128 |
demo.launch(inbrowser=True)
|
129 |
+
"""
|
130 |
|
131 |
'''
|
132 |
def get_image_name(_image):
|