Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
# Configura莽茫o do diret贸rio de armazenamento
|
| 5 |
+
STORAGE_DIR = "storage"
|
| 6 |
+
|
| 7 |
+
# Criar o diret贸rio de armazenamento se n茫o existir
|
| 8 |
+
if not os.path.exists(STORAGE_DIR):
|
| 9 |
+
os.makedirs(STORAGE_DIR)
|
| 10 |
+
|
| 11 |
+
# Fun莽茫o para listar arquivos
|
| 12 |
+
def list_files(directory):
|
| 13 |
+
file_tree = {}
|
| 14 |
+
for root, dirs, files in os.walk(directory):
|
| 15 |
+
for name in files:
|
| 16 |
+
folder_path = os.path.relpath(root, directory)
|
| 17 |
+
if folder_path not in file_tree:
|
| 18 |
+
file_tree[folder_path] = []
|
| 19 |
+
file_tree[folder_path].append(name)
|
| 20 |
+
return file_tree
|
| 21 |
+
|
| 22 |
+
# Interface do Streamlit
|
| 23 |
+
st.title("Gerenciamento de Armazenamento em Nuvem")
|
| 24 |
+
|
| 25 |
+
# Upload de arquivo
|
| 26 |
+
uploaded_file = st.file_uploader("Escolha um arquivo para enviar")
|
| 27 |
+
if uploaded_file is not None:
|
| 28 |
+
file_path = os.path.join(STORAGE_DIR, uploaded_file.name)
|
| 29 |
+
with open(file_path, "wb") as f:
|
| 30 |
+
f.write(uploaded_file.getbuffer())
|
| 31 |
+
st.success(f"Arquivo {uploaded_file.name} enviado com sucesso!")
|
| 32 |
+
|
| 33 |
+
# Exibir arquivos
|
| 34 |
+
st.header("Arquivos no Armazenamento")
|
| 35 |
+
files = list_files(STORAGE_DIR)
|
| 36 |
+
for folder, files in files.items():
|
| 37 |
+
st.subheader(folder)
|
| 38 |
+
for file in files:
|
| 39 |
+
st.text(file)
|
| 40 |
+
|
| 41 |
+
# Deletar arquivo
|
| 42 |
+
st.header("Deletar Arquivo")
|
| 43 |
+
file_to_delete = st.text_input("Digite o caminho do arquivo para deletar (ex: subpasta/nome_do_arquivo.txt)")
|
| 44 |
+
if st.button("Deletar"):
|
| 45 |
+
if file_to_delete:
|
| 46 |
+
abs_path = os.path.join(STORAGE_DIR, file_to_delete)
|
| 47 |
+
if os.path.isfile(abs_path):
|
| 48 |
+
os.remove(abs_path)
|
| 49 |
+
st.success(f"Arquivo {file_to_delete} deletado com sucesso!")
|
| 50 |
+
else:
|
| 51 |
+
st.error(f"Arquivo {file_to_delete} n茫o encontrado!")
|