Spaces:
Sleeping
Sleeping
Create apppy.py
Browse files
apppy.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import zipfile
|
4 |
+
from spacy2 import classifica_e_sposta_documenti
|
5 |
+
|
6 |
+
st.title('Categorizzazione Documenti')
|
7 |
+
|
8 |
+
uploaded_file = st.file_uploader("Carica un file ZIP contenente i documenti", type="zip")
|
9 |
+
|
10 |
+
if uploaded_file is not None:
|
11 |
+
# Salva il file ZIP caricato in una directory temporanea
|
12 |
+
with open("temp.zip", "wb") as f:
|
13 |
+
f.write(uploaded_file.getbuffer())
|
14 |
+
|
15 |
+
# Estrai il file ZIP
|
16 |
+
with zipfile.ZipFile("temp.zip", 'r') as zip_ref:
|
17 |
+
zip_ref.extractall("temp")
|
18 |
+
|
19 |
+
# Elabora ogni file nella directory estratta
|
20 |
+
for file_name in os.listdir("temp"):
|
21 |
+
classifica_e_sposta_documenti("temp", file_name)
|
22 |
+
|
23 |
+
# Ricomprimi i file processati in un nuovo file ZIP
|
24 |
+
with zipfile.ZipFile('processed.zip', 'w') as zipf:
|
25 |
+
for root, dirs, files in os.walk("temp"):
|
26 |
+
for file in files:
|
27 |
+
zipf.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), "temp"))
|
28 |
+
|
29 |
+
# Fornisci il file ZIP per il download
|
30 |
+
with open('processed.zip', 'rb') as f:
|
31 |
+
st.download_button('Scarica File Processati', f, file_name='processed.zip')
|
32 |
+
|
33 |
+
# Pulisci i file temporanei
|
34 |
+
if st.button('Pulisci'):
|
35 |
+
os.remove("temp.zip")
|
36 |
+
os.remove("processed.zip")
|
37 |
+
shutil.rmtree("temp")
|