Spaces:
Runtime error
Runtime error
File size: 2,193 Bytes
3d5b1a3 9501a09 3d5b1a3 9501a09 03b3462 3d5b1a3 9501a09 28e3cfd 9501a09 28e3cfd 9501a09 573bc06 9501a09 28e3cfd 9501a09 28e3cfd 9501a09 3d5b1a3 9501a09 3d5b1a3 9501a09 3d5b1a3 9501a09 3d5b1a3 9501a09 3d5b1a3 9501a09 573bc06 |
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 |
import os
import gradio as gr
# Configuração do diretório de armazenamento
STORAGE_DIR = "storage"
# Criar o diretório de armazenamento se não existir
if not os.path.exists(STORAGE_DIR):
os.makedirs(STORAGE_DIR)
# Função para upload de arquivos
def upload_file(file):
# Salvar o arquivo no diretório de armazenamento
file_path = os.path.join(STORAGE_DIR, file.name)
with open(file_path, "wb") as f:
f.write(file) # Escrever o conteúdo diretamente
return "Arquivo enviado com sucesso!"
# Função para listar arquivos
def list_files():
file_tree = {}
for root, dirs, files in os.walk(STORAGE_DIR):
for name in files:
folder_path = os.path.relpath(root, STORAGE_DIR)
if folder_path not in file_tree:
file_tree[folder_path] = []
file_tree[folder_path].append(name)
return file_tree
# Função para deletar arquivos
def delete_file(file_path):
abs_path = os.path.join(STORAGE_DIR, file_path)
if os.path.isfile(abs_path):
os.remove(abs_path)
return f"Arquivo {file_path} deletado com sucesso!"
else:
return f"Arquivo {file_path} não encontrado!"
# Interface Gradio
def file_explorer_ui():
with gr.Blocks() as demo:
gr.Markdown("# Gerenciamento de Armazenamento em Nuvem")
with gr.Row():
with gr.Column():
upload = gr.File(label="Enviar Arquivo")
upload_btn = gr.Button("Enviar")
upload_output = gr.Textbox()
with gr.Column():
delete_file_input = gr.Textbox(label="Caminho do arquivo para deletar")
delete_file_btn = gr.Button("Deletar")
delete_output = gr.Textbox()
with gr.Row():
list_files_btn = gr.Button("Listar Arquivos")
file_list_output = gr.JSON()
upload_btn.click(upload_file, inputs=upload, outputs=upload_output)
delete_file_btn.click(delete_file, inputs=delete_file_input, outputs=delete_output)
list_files_btn.click(list_files, outputs=file_list_output)
return demo
# Rodar a aplicação
file_explorer_ui().launch(share=True)
|