Update app.py
Browse files
app.py
CHANGED
|
@@ -7,13 +7,14 @@ from sklearn.metrics.pairwise import cosine_similarity
|
|
| 7 |
import numpy as np
|
| 8 |
import zipfile
|
| 9 |
|
|
|
|
| 10 |
|
| 11 |
-
# Funzione per estrarre ed
|
| 12 |
def extract_zip(file):
|
| 13 |
if not zipfile.is_zipfile(file.name):
|
| 14 |
return "Errore: Il file caricato non è uno ZIP valido."
|
| 15 |
|
| 16 |
-
# Percorso per
|
| 17 |
extraction_dir = "./extracted_files"
|
| 18 |
os.makedirs(extraction_dir, exist_ok=True)
|
| 19 |
|
|
@@ -21,24 +22,26 @@ def extract_zip(file):
|
|
| 21 |
with zipfile.ZipFile(file.name, 'r') as zip_ref:
|
| 22 |
zip_ref.extractall(extraction_dir)
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
for root, dirs, files in os.walk(extraction_dir):
|
| 27 |
for f in files:
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
return f"File estratti nella directory '{extraction_dir}':\n" + "\n".join(extracted_files)
|
| 32 |
|
| 33 |
# Interfaccia Gradio
|
| 34 |
interface = gr.Interface(
|
| 35 |
fn=extract_zip,
|
| 36 |
inputs=gr.File(label="Carica il file ZIP"),
|
| 37 |
outputs="text",
|
| 38 |
-
title="Estrattore ZIP",
|
| 39 |
-
description="Carica un file ZIP. I file verranno estratti e
|
| 40 |
)
|
| 41 |
|
| 42 |
# Avvia l'applicazione
|
| 43 |
if __name__ == "__main__":
|
| 44 |
interface.launch()
|
|
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
import zipfile
|
| 9 |
|
| 10 |
+
import shutil
|
| 11 |
|
| 12 |
+
# Funzione per estrarre ed esporre i file
|
| 13 |
def extract_zip(file):
|
| 14 |
if not zipfile.is_zipfile(file.name):
|
| 15 |
return "Errore: Il file caricato non è uno ZIP valido."
|
| 16 |
|
| 17 |
+
# Percorso temporaneo per l'estrazione
|
| 18 |
extraction_dir = "./extracted_files"
|
| 19 |
os.makedirs(extraction_dir, exist_ok=True)
|
| 20 |
|
|
|
|
| 22 |
with zipfile.ZipFile(file.name, 'r') as zip_ref:
|
| 23 |
zip_ref.extractall(extraction_dir)
|
| 24 |
|
| 25 |
+
# Sposta i file nella radice del progetto per renderli visibili
|
| 26 |
+
project_dir = "./"
|
| 27 |
for root, dirs, files in os.walk(extraction_dir):
|
| 28 |
for f in files:
|
| 29 |
+
source_path = os.path.join(root, f)
|
| 30 |
+
dest_path = os.path.join(project_dir, f)
|
| 31 |
+
shutil.move(source_path, dest_path)
|
| 32 |
|
| 33 |
+
return "File estratti e copiati nella radice del progetto:\n" + "\n".join(os.listdir(project_dir))
|
|
|
|
| 34 |
|
| 35 |
# Interfaccia Gradio
|
| 36 |
interface = gr.Interface(
|
| 37 |
fn=extract_zip,
|
| 38 |
inputs=gr.File(label="Carica il file ZIP"),
|
| 39 |
outputs="text",
|
| 40 |
+
title="Estrattore ZIP e Copia nella Radice",
|
| 41 |
+
description="Carica un file ZIP. I file verranno estratti e resi visibili nella radice del progetto."
|
| 42 |
)
|
| 43 |
|
| 44 |
# Avvia l'applicazione
|
| 45 |
if __name__ == "__main__":
|
| 46 |
interface.launch()
|
| 47 |
+
|