elismasilva commited on
Commit
f8bb6fc
·
verified ·
1 Parent(s): f63d6e2

Update src/demo/app.py

Browse files
Files changed (1) hide show
  1. src/demo/app.py +61 -61
src/demo/app.py CHANGED
@@ -1,62 +1,62 @@
1
- import gradio as gr
2
- from gradio_folderexplorer import FolderExplorer
3
- from gradio_folderexplorer.helpers import load_media_from_folder
4
- from PIL import Image
5
- import os
6
-
7
- # --- Configuration Constants ---
8
-
9
- # Define the root directory for the FolderExplorer to start in.
10
- # All browsable folders will be relative to this path.
11
- ROOT_DIR_PATH = "./examples"
12
-
13
- # --- UI Layout and Logic ---
14
-
15
- # Create the user interface using Gradio Blocks.
16
- with gr.Blocks(theme=gr.themes.Ocean()) as demo:
17
- # A single row is used to create a side-by-side layout.
18
- gr.Markdown("# FolderExplorer Component Demo")
19
- with gr.Row(equal_height=True):
20
- # The first column contains the custom folder explorer component.
21
- with gr.Column(scale=1, min_width=300):
22
- folder_explorer = FolderExplorer(
23
- label="Select a Folder",
24
- root_dir=ROOT_DIR_PATH,
25
- # Set the initial selected value to the root directory itself.
26
- # This is used by the demo.load() event.
27
- value=ROOT_DIR_PATH
28
- )
29
-
30
- # The second column contains the gallery to display the media.
31
- with gr.Column(scale=3):
32
- gallery = gr.Gallery(
33
- label="Selected Images",
34
- columns=6,
35
- height="auto",
36
- )
37
-
38
- # --- Event Handling ---
39
-
40
- # 1. Event for user interaction:
41
- # When the user selects a new folder in the FolderExplorer, the .change() event
42
- # is triggered. The `load_media_from_folder` helper is called with the new
43
- # folder path, and its output populates the gallery.
44
- folder_explorer.change(
45
- fn=load_media_from_folder,
46
- inputs=folder_explorer,
47
- outputs=gallery
48
- )
49
-
50
- # 2. Event for initial page load:
51
- # This event runs once when the app starts. It takes the initial `value` of the
52
- # folder_explorer ('ROOT_DIR_PATH'), passes it to the helper function,
53
- # and populates the gallery with the media from the root directory.
54
- demo.load(
55
- fn=load_media_from_folder,
56
- inputs=folder_explorer,
57
- outputs=gallery
58
- )
59
-
60
- # --- Application Launch ---
61
- if __name__ == "__main__":
62
  demo.launch()
 
1
+ import gradio as gr
2
+ from gradio_folderexplorer import FolderExplorer
3
+ from gradio_folderexplorer.helpers import load_media_from_folder
4
+ from PIL import Image
5
+ import os
6
+
7
+ # --- Configuration Constants ---
8
+
9
+ # Define the root directory for the FolderExplorer to start in.
10
+ # All browsable folders will be relative to this path.
11
+ ROOT_DIR_PATH = "./src/examples"
12
+
13
+ # --- UI Layout and Logic ---
14
+
15
+ # Create the user interface using Gradio Blocks.
16
+ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
17
+ # A single row is used to create a side-by-side layout.
18
+ gr.Markdown("# FolderExplorer Component Demo")
19
+ with gr.Row(equal_height=True):
20
+ # The first column contains the custom folder explorer component.
21
+ with gr.Column(scale=1, min_width=300):
22
+ folder_explorer = FolderExplorer(
23
+ label="Select a Folder",
24
+ root_dir=ROOT_DIR_PATH,
25
+ # Set the initial selected value to the root directory itself.
26
+ # This is used by the demo.load() event.
27
+ value=ROOT_DIR_PATH
28
+ )
29
+
30
+ # The second column contains the gallery to display the media.
31
+ with gr.Column(scale=3):
32
+ gallery = gr.Gallery(
33
+ label="Selected Images",
34
+ columns=6,
35
+ height="auto",
36
+ )
37
+
38
+ # --- Event Handling ---
39
+
40
+ # 1. Event for user interaction:
41
+ # When the user selects a new folder in the FolderExplorer, the .change() event
42
+ # is triggered. The `load_media_from_folder` helper is called with the new
43
+ # folder path, and its output populates the gallery.
44
+ folder_explorer.change(
45
+ fn=load_media_from_folder,
46
+ inputs=folder_explorer,
47
+ outputs=gallery
48
+ )
49
+
50
+ # 2. Event for initial page load:
51
+ # This event runs once when the app starts. It takes the initial `value` of the
52
+ # folder_explorer ('ROOT_DIR_PATH'), passes it to the helper function,
53
+ # and populates the gallery with the media from the root directory.
54
+ demo.load(
55
+ fn=load_media_from_folder,
56
+ inputs=folder_explorer,
57
+ outputs=gallery
58
+ )
59
+
60
+ # --- Application Launch ---
61
+ if __name__ == "__main__":
62
  demo.launch()