MisterAI commited on
Commit
c5f5c24
·
verified ·
1 Parent(s): 71c3e10

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #BS_app.py_05_LIST_CREATE_FOLDER
2
+ ##Trying List And Create SubFolder
3
+
4
+ import gradio as gr
5
+ from huggingface_hub import HfApi
6
+
7
+ def list_repo_content(repo_path):
8
+ api = HfApi()
9
+ repo_id = repo_path.split("/")[0]
10
+ repo_info = api.repo_info(repo_id)
11
+ content = repo_info["subdirectories"] + repo_info["files"]
12
+ return content
13
+
14
+ def create_subfolder(repo_path, subfolder_name):
15
+ api = HfApi()
16
+ repo_id = repo_path.split("/")[0]
17
+ subfolder_path = f"{repo_path}/{subfolder_name}"
18
+ api.create_folder(repo_id, subfolder_path)
19
+ return f"Sous-répertoire {subfolder_path} créé avec succès."
20
+
21
+ with gr.Blocks() as demo:
22
+ with gr.Row():
23
+ repo_path = gr.Textbox(label="Chemin du dépôt")
24
+ list_button = gr.Button("Lister le contenu")
25
+ create_button = gr.Button("Créer un sous-répertoire")
26
+ subfolder_name = gr.Textbox(label="Nom du sous-répertoire")
27
+
28
+ with gr.Row():
29
+ repo_content = gr.Textbox(label="Contenu du dépôt")
30
+
31
+ list_button.click(
32
+ list_repo_content,
33
+ inputs=repo_path,
34
+ outputs=repo_content
35
+ )
36
+
37
+ create_button.click(
38
+ create_subfolder,
39
+ inputs=[repo_path, subfolder_name],
40
+ outputs=repo_content
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ demo.launch()