udayjawheri commited on
Commit
95c2369
·
verified ·
1 Parent(s): 4d2a77d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -8,18 +8,35 @@ def list_files_and_subfolders():
8
  # List files and subfolders in the current directory
9
  files_and_subfolders = os.listdir(current_directory)
10
 
11
- # Convert list to string for display
12
- files_and_subfolders_str = "\n".join(files_and_subfolders)
13
 
14
- return files_and_subfolders_str
 
 
 
 
 
15
 
16
- # Gradio interface
17
- interface = gr.Interface(
 
 
18
  fn=list_files_and_subfolders,
19
  inputs=None, # No inputs required
 
 
 
 
 
 
 
 
 
20
  outputs="text",
21
- title="List Files and Subfolders in Current Directory",
22
- description="List all files and subfolders in the current directory.",
23
  )
24
 
25
- interface.launch()
 
 
 
8
  # List files and subfolders in the current directory
9
  files_and_subfolders = os.listdir(current_directory)
10
 
11
+ return files_and_subfolders
 
12
 
13
+ def get_selected_item(selected_item):
14
+ # Get the current directory
15
+ current_directory = os.getcwd()
16
+
17
+ # Construct the path of the selected item
18
+ selected_item_path = os.path.join(current_directory, selected_item)
19
 
20
+ return selected_item_path
21
+
22
+ # Gradio interface to list files and subfolders
23
+ interface_list = gr.Interface(
24
  fn=list_files_and_subfolders,
25
  inputs=None, # No inputs required
26
+ outputs=gr.outputs.CheckboxGroup(label="Files and Subfolders"),
27
+ title="List Files and Subfolders",
28
+ description="Select a file or folder from the list.",
29
+ )
30
+
31
+ # Gradio interface to get selected item path
32
+ interface_get_path = gr.Interface(
33
+ fn=get_selected_item,
34
+ inputs=gr.inputs.CheckboxGroup(label="Select Item", type="file"),
35
  outputs="text",
36
+ title="Get Selected Item Path",
37
+ description="Get the path of the selected file or folder.",
38
  )
39
 
40
+ # Launch both interfaces
41
+ interface_list.launch()
42
+ interface_get_path.launch()