udayjawheri commited on
Commit
b11faef
·
verified ·
1 Parent(s): 68a39ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -19
app.py CHANGED
@@ -1,28 +1,25 @@
1
  import gradio as gr
 
2
 
3
- def list_subfolders(dataset_path):
4
- """Lists all subfolders within the provided dataset path.
 
5
 
6
- Args:
7
- dataset_path: The path to the dataset directory.
8
 
9
- Returns:
10
- A list of subfolder names or an empty list if no subfolders exist.
11
- """
12
- try:
13
- import os
14
- return [f for f in os.listdir(dataset_path) if os.path.isdir(os.path.join(dataset_path, f))]
15
- except FileNotFoundError:
16
- return ["Dataset path not found!"]
17
- except PermissionError:
18
- return ["Permission error accessing path!"]
19
 
 
 
 
 
20
  interface = gr.Interface(
21
- fn=list_subfolders,
22
- inputs="text",
23
- outputs="list",
24
- title="List Subfolders",
25
- description="Enter the path to your dataset directory and see a list of subfolders.",
26
  )
27
 
28
  interface.launch()
 
1
  import gradio as gr
2
+ from datasets import list_datasets, list_files
3
 
4
+ def list_files_and_subfolders(dataset_name):
5
+ # List files and subfolders in the chosen dataset directory
6
+ files_and_subfolders = list_files(dataset_name)
7
 
8
+ # Convert list to string for display
9
+ files_and_subfolders_str = "\n".join(files_and_subfolders)
10
 
11
+ return files_and_subfolders_str
 
 
 
 
 
 
 
 
 
12
 
13
+ # List all available datasets
14
+ datasets = list_datasets()
15
+
16
+ # Gradio interface
17
  interface = gr.Interface(
18
+ fn=list_files_and_subfolders,
19
+ inputs=gr.inputs.Dropdown(choices=datasets, label="Choose Dataset"),
20
+ outputs="text",
21
+ title="List Files and Subfolders in Hugging Face Dataset",
22
+ description="Choose a dataset to list its files and subfolders.",
23
  )
24
 
25
  interface.launch()