Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,14 +10,31 @@ import requests
|
|
10 |
from io import BytesIO
|
11 |
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
# Récupérer token depuis les variables d'environnement
|
14 |
hf_token = os.getenv("MisterAI_bigscience_bloom_560m")
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# Créer une instance de HfFileSystem
|
23 |
fs = HfFileSystem()
|
@@ -28,35 +45,6 @@ def list_repo_content(repo_path):
|
|
28 |
content = repo_info["subdirectories"] + repo_info["files"]
|
29 |
return content
|
30 |
|
31 |
-
def create_subfolder(repo_path, subfolder_name):
|
32 |
-
repo_id = repo_path.split("/")[0]
|
33 |
-
subfolder_path = f"{repo_path}/{subfolder_name}"
|
34 |
-
fs.mkdir(subfolder_path)
|
35 |
-
return f"Sous-répertoire {subfolder_path} créé avec succès."
|
36 |
-
|
37 |
-
with gr.Blocks() as demo:
|
38 |
-
with gr.Row():
|
39 |
-
repo_path = gr.Textbox(label="Chemin du dépôt")
|
40 |
-
list_button = gr.Button("Lister le contenu")
|
41 |
-
create_button = gr.Button("Créer un sous-répertoire")
|
42 |
-
subfolder_name = gr.Textbox(label="Nom du sous-répertoire")
|
43 |
-
|
44 |
-
# Récupérer token depuis les variables d'environnement
|
45 |
-
hf_token = os.getenv("MisterAI_bigscience_bloom_560m")
|
46 |
-
|
47 |
-
# Configurer le token pour l'utilisation avec Hugging Face
|
48 |
-
if hf_token:
|
49 |
-
HfFolder.save_token(hf_token)
|
50 |
-
else:
|
51 |
-
raise ValueError("Le token Hugging Face n'est pas configuré. Assurez-vous qu'il est défini dans les variables d'environnement.")
|
52 |
-
|
53 |
-
def list_repo_content(repo_path):
|
54 |
-
api = HfApi()
|
55 |
-
repo_id = repo_path.split("/")[0]
|
56 |
-
repo_info = api.repo_info(repo_id)
|
57 |
-
content = repo_info["subdirectories"] + repo_info["files"]
|
58 |
-
return content
|
59 |
-
|
60 |
def create_subfolder(repo_path, subfolder_name):
|
61 |
api = HfApi()
|
62 |
repo_id = repo_path.split("/")[0]
|
@@ -64,6 +52,8 @@ def create_subfolder(repo_path, subfolder_name):
|
|
64 |
api.create_folder(repo_id, subfolder_path)
|
65 |
return f"Sous-répertoire {subfolder_path} créé avec succès."
|
66 |
|
|
|
|
|
67 |
with gr.Blocks() as demo:
|
68 |
with gr.Row():
|
69 |
repo_path = gr.Textbox(label="Chemin du dépôt")
|
@@ -87,27 +77,7 @@ with gr.Blocks() as demo:
|
|
87 |
)
|
88 |
|
89 |
if __name__ == "__main__":
|
|
|
90 |
demo.launch()
|
91 |
|
92 |
-
with gr.Row():
|
93 |
-
repo_content = gr.Textbox(label="Contenu du dépôt")
|
94 |
-
|
95 |
-
list_button.click(
|
96 |
-
list_repo_content,
|
97 |
-
inputs=repo_path,
|
98 |
-
outputs=repo_content
|
99 |
-
)
|
100 |
-
|
101 |
-
create_button.click(
|
102 |
-
create_subfolder,
|
103 |
-
inputs=[repo_path, subfolder_name],
|
104 |
-
outputs=repo_content
|
105 |
-
)
|
106 |
-
|
107 |
-
if __name__ == "__main__":
|
108 |
-
demo.launch()
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
|
|
|
10 |
from io import BytesIO
|
11 |
|
12 |
|
13 |
+
|
14 |
+
import gradio as gr
|
15 |
+
import os
|
16 |
+
from huggingface_hub import HfFileSystem, HfApi
|
17 |
+
|
18 |
# Récupérer token depuis les variables d'environnement
|
19 |
hf_token = os.getenv("MisterAI_bigscience_bloom_560m")
|
20 |
|
21 |
+
# Fenêtre d'authentification
|
22 |
+
with gr.Blocks() as auth_demo:
|
23 |
+
hf_token_input = gr.Textbox(label="Hugging Face Token")
|
24 |
+
auth_button = gr.Button("Authentifier")
|
25 |
+
|
26 |
+
def authenticate(hf_token):
|
27 |
+
# Configurer le token pour l'utilisation avec Hugging Face
|
28 |
+
if hf_token:
|
29 |
+
HfFolder.save_token(hf_token)
|
30 |
+
else:
|
31 |
+
raise ValueError("Le token Hugging Face n'est pas configuré. Assurez-vous qu'il est défini dans les variables d'environnement.")
|
32 |
+
|
33 |
+
auth_button.click(
|
34 |
+
authenticate,
|
35 |
+
inputs=hf_token_input,
|
36 |
+
outputs=gr.Textbox(value="Authentification réussie", visible=False)
|
37 |
+
)
|
38 |
|
39 |
# Créer une instance de HfFileSystem
|
40 |
fs = HfFileSystem()
|
|
|
45 |
content = repo_info["subdirectories"] + repo_info["files"]
|
46 |
return content
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def create_subfolder(repo_path, subfolder_name):
|
49 |
api = HfApi()
|
50 |
repo_id = repo_path.split("/")[0]
|
|
|
52 |
api.create_folder(repo_id, subfolder_path)
|
53 |
return f"Sous-répertoire {subfolder_path} créé avec succès."
|
54 |
|
55 |
+
|
56 |
+
|
57 |
with gr.Blocks() as demo:
|
58 |
with gr.Row():
|
59 |
repo_path = gr.Textbox(label="Chemin du dépôt")
|
|
|
77 |
)
|
78 |
|
79 |
if __name__ == "__main__":
|
80 |
+
auth_demo.launch()
|
81 |
demo.launch()
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|