File size: 4,110 Bytes
2fa18c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
current_file_path = Path(__file__).resolve()
relative_path = "path/to/file"
absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve()


def get_file_content(file):
    return (file,)


with gr.Blocks() as demo:
    gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`')
    submit_btn = gr.Button("Select")
    with gr.Row():
        file = gr.FileExplorer(
            glob="**/components/*.py",
            # value=["themes/utils"],
            root_dir=absolute_path,
            ignore_glob="**/__init__.py",
        )

        file2 = gr.FileExplorer(
            glob="**/components/**/*.py",
            root_dir=absolute_path,
            ignore_glob="**/__init__.py",
        )
    submit_btn.click(lambda x: x, file, file2)

    gr.Markdown("---")
    gr.Markdown('### `FileExplorer` to `Code` -- `file_count="single"`')
    with gr.Group():
        with gr.Row():
            file_3 = gr.FileExplorer(
                scale=1,
                glob="**/components/**/*.py",
                value=["themes/utils"],
                file_count="single",
                root_dir=absolute_path,
                ignore_glob="**/__init__.py",
                elem_id="file",
            )

            code = gr.Code(lines=30, scale=2, language="python")

    file_3.change(get_file_content, file_3, code)

if __name__ == "__main__":
    demo.launch()
"""

""" Version 1
def display_name_files(_folder_path):
    return f"{[img_name for img_name in os.listdir(_folder_path)]} \n"


def on_browse(data_type):
    root = Tk()
    root.attributes("-topmost", True)
    root.withdraw()
    if data_type == "Files":
        filenames = filedialog.askopenfilenames()
        if len(filenames) > 0:
            root.destroy()
            return str(filenames)
        else:
            filename = "Files not seleceted"
            root.destroy()
            return str(filename)

    elif data_type == "Folder":
        filename = filedialog.askdirectory()
        print(filename)
        print(type(filename))
        if filename:
            if os.path.isdir(filename):
                root.destroy()
                return str("\n".join(os.listdir(filename)))
                # return str(filename)
            else:
                root.destroy()
                return str(filename)
        else:
            filename = "Folder not seleceted"
            root.destroy()
            return str(filename)


def main():
    with gr.Blocks() as demo:
        data_type = gr.Radio(
            choices=["Files", "Folder"], value="Files", label="Offline data type"
        )
        input_path = gr.Textbox(
            label="Select Multiple videos", scale=5, interactive=False
        )
        image_browse_btn = gr.Button("Browse", min_width=1)
        image_browse_btn.click(
            on_browse, inputs=data_type, outputs=input_path, show_progress="hidden"
        )
    return demo


demo = main()
demo.launch(inbrowser=True)
"""

'''
def get_image_name(_image):
    if _image.any():
        # print(type(_image))
        output_info = f"""
        Image shape: 
        {_image.shape}
        """
        return output_info
    else:
        return "No file uploaded"


def list_images(dir):
    return [d.name for d in dir]


with gr.Blocks() as interface:
    gr.Markdown("Import your image and then click the button to see the output.")
    with gr.Row():
        input_img = gr.Image(label="Input Image", height=500, width=500)
        # output_img = gr.Image(label="Recognized Image")
        # display_df = gr.DataFrame(export_results)
        output_info = gr.Textbox()
        # export_info = gr.Textbox()
    labelling_btn = gr.Button("Apply Species Recognition")
    # export_btn = gr.Button("Export result as a CSV")
    labelling_btn.click(fn=get_image_name, inputs=input_img, outputs=[output_info])
    # export_btn.click(fn=export_results, inputs=input_img, outputs=[export_info])

    with gr.Row():
        gr.Dataframe(pd.DataFrame({"col1": [1, 2], "col2": [3, 4]}))

# Launch the app
if __name__ == "__main__":
    interface.launch()
'''