Spaces:
Sleeping
Sleeping
Update appli_demo.py
Browse files- appli_demo.py +41 -0
appli_demo.py
CHANGED
|
@@ -37,6 +37,47 @@ if not os.path.exists(TARGET_FOLDER):
|
|
| 37 |
if os.path.exists("CheXpert-v1.0-small"):
|
| 38 |
st.write("📁 Dossiers détectés à l'intérieur de CheXpert-v1.0-small :", os.listdir("CheXpert-v1.0-small"))
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# 1. Configuration de la page
|
| 41 |
st.set_page_config(page_title="MIROIR", layout="wide")
|
| 42 |
st.markdown("### 🩺 MIROIR : Modèle d'Intelligence pour le Rapprochement d'Observations, d'Images et de Rapports")
|
|
|
|
| 37 |
if os.path.exists("CheXpert-v1.0-small"):
|
| 38 |
st.write("📁 Dossiers détectés à l'intérieur de CheXpert-v1.0-small :", os.listdir("CheXpert-v1.0-small"))
|
| 39 |
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# 🟢 FONCTION DE DÉCOMPRESSION UNIQUE AVEC MISE EN CACHE
|
| 43 |
+
@st.cache_resource
|
| 44 |
+
def initialiser_images_demo():
|
| 45 |
+
TARGET_FOLDER = "CheXpert-v1.0-small"
|
| 46 |
+
if os.path.exists(TARGET_FOLDER):
|
| 47 |
+
return True
|
| 48 |
+
# Étape 2 : Si le dossier n'est pas là, on cherche le ZIP pour l'extraire
|
| 49 |
+
if os.path.exists("mini_chexpert.zip"):
|
| 50 |
+
try:
|
| 51 |
+
with zipfile.ZipFile("mini_chexpert.zip", 'r') as zip_ref:
|
| 52 |
+
liste_fichiers = zip_ref.infolist()
|
| 53 |
+
total_fichiers = len(liste_fichiers)
|
| 54 |
+
# Composants visuels éphémères
|
| 55 |
+
barre_progression = st.progress(0)
|
| 56 |
+
statut_texte = st.empty()
|
| 57 |
+
for index, fichier in enumerate(liste_fichiers, 1):
|
| 58 |
+
zip_ref.extract(fichier, path=".")
|
| 59 |
+
if index % 10 == 0 or index == total_fichiers:
|
| 60 |
+
barre_progression.progress(index / total_fichiers)
|
| 61 |
+
statut_texte.text(f"Extraction des radiographies : {index}/{total_fichiers}")
|
| 62 |
+
# On efface les jauges une fois fini
|
| 63 |
+
barre_progression.empty()
|
| 64 |
+
statut_texte.empty()
|
| 65 |
+
return True
|
| 66 |
+
except Exception as e:
|
| 67 |
+
st.error(f"❌ Erreur technique lors de l'extraction : {e}")
|
| 68 |
+
return False
|
| 69 |
+
# Étape 3 : Si ni le dossier ni le ZIP n'existent
|
| 70 |
+
else:
|
| 71 |
+
st.error("❌ Erreur critique : Le dossier d'images et le fichier 'mini_chexpert.zip' sont introuvables.")
|
| 72 |
+
return False
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# 🟢 EXÉCUTION DE LA FONCTION
|
| 76 |
+
# Grâce au cache Streamlit, au premier clic le ZIP s'extrait.
|
| 77 |
+
# Aux clics suivants, cette ligne renvoie instantanément "True" sans rien afficher à l'écran.
|
| 78 |
+
images_pretes = initialiser_images_demo()
|
| 79 |
+
|
| 80 |
+
|
| 81 |
# 1. Configuration de la page
|
| 82 |
st.set_page_config(page_title="MIROIR", layout="wide")
|
| 83 |
st.markdown("### 🩺 MIROIR : Modèle d'Intelligence pour le Rapprochement d'Observations, d'Images et de Rapports")
|