File size: 2,365 Bytes
c5f5c24
 
 
 
08ae3bc
 
 
18e275a
08ae3bc
 
 
1e5a9f9
 
 
 
6a453da
216fa04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e5a9f9
 
 
 
 
 
 
 
 
c5f5c24
 
 
 
 
 
 
3606014
c5f5c24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed0b0ac
c5f5c24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#BS_app.py_05_LIST_CREATE_FOLDER
##Trying List And Create SubFolder 

import gradio as gr
import os
from transformers import AutoModelForCausalLM, AutoTokenizer, Trainer, TrainingArguments, DataCollatorForLanguageModeling
from datasets import load_dataset, Dataset
from huggingface_hub import HfApi, HfFolder, HfFileSystem
import requests
from io import BytesIO


# Récupérer token depuis les variables d'environnement
hf_token = os.getenv("MisterAI_bigscience_bloom_560m")

# Fenêtre d'authentification
#with gr.Blocks() as auth_demo:
#    hf_token_input = gr.Textbox(label="Hugging Face Token")
#    auth_button = gr.Button("Authentifier")
#
#    def authenticate(hf_token):
#        # Configurer le token pour l'utilisation avec Hugging Face
#        if hf_token:
#            HfFolder.save_token(hf_token)
#        else:
#            raise ValueError("Le token Hugging Face n'est pas configuré. Assurez-vous qu'il est défini dans les variables d'environnement.")
#
#    auth_button.click(
#        authenticate,
#        inputs=hf_token_input,
#        outputs=gr.Textbox(value="Authentification réussie", visible=False)
#    )
#
# Créer une instance de HfFileSystem
fs = HfFileSystem()

def list_repo_content(repo_path):
    repo_id = repo_path.split("/")[0]
    repo_info = fs.info(repo_id)
    content = repo_info["subdirectories"] + repo_info["files"]
    return content

def create_subfolder(repo_path, subfolder_name):
    api = HfApi()
    repo_id = repo_path.split("/")[0]
    subfolder_path = f"{repo_path}/{subfolder_name}"
    api.create_folder(repo_id, subfolder_path)
    return f"Sous-répertoire {subfolder_path} créé avec succès."

# Interface Gradio
with gr.Blocks() as demo:
    with gr.Row():
        repo_path = gr.Textbox(label="Chemin du dépôt")
        list_button = gr.Button("Lister le contenu")
        create_button = gr.Button("Créer un sous-répertoire")
        subfolder_name = gr.Textbox(label="Nom du sous-répertoire")

    with gr.Row():
        repo_content = gr.Textbox(label="Contenu du dépôt")

    list_button.click(
        list_repo_content,
        inputs=repo_path,
        outputs=repo_content
    )

    create_button.click(
        create_subfolder,
        inputs=[repo_path, subfolder_name],
        outputs=repo_content
    )

if __name__ == "__main__":
#    auth_demo.launch()
    demo.launch()