Spaces:
Runtime error
Runtime error
Download src/streamlit_app.py from Lubilange2/cvv: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/spaces/Lubilange2/cvv/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/Lubilange2/cvv/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/Lubilange2/cvv/resolve/main/src/streamlit_app.py
1.61 kB
| import streamlit as st | |
| from PIL import Image | |
| import numpy as np | |
| import tensorflow as tf | |
| import os | |
| import uuid | |
| from io import BytesIO | |
| # Chargement du modèle | |
| model = tf.keras.models.load_model("modele_ia.h5", compile=False) | |
| classes = ['fertile', 'non_fertile'] | |
| def predict_image(img): | |
| img = img.resize((224, 224)) | |
| img_array = np.array(img) / 255.0 | |
| img_array = np.reshape(img_array, [-1, 224, 224, 3]) | |
| prediction = model.predict(img_array) | |
| predicted_class = classes[np.argmax(prediction)] | |
| return predicted_class | |
| st.title("Classification d'image : Fertile / Non Fertile") | |
| st.write("Upload une image pour analyser sa fertilité.") | |
| uploaded_files = st.file_uploader("Choisir une image", type=["jpg", "jpeg", "png"], accept_multiple_files=True) | |
| if uploaded_files: | |
| for uploaded_file in uploaded_files: | |
| # Lire les données binaires et les convertir en image | |
| image_data = uploaded_file.read() | |
| image = Image.open(BytesIO(image_data)).convert("RGB") | |
| st.image(image, caption=uploaded_file.name, use_column_width=True) | |
| if st.button(f"Prédire {uploaded_file.name}"): | |
| result = predict_image(image) | |
| st.success(f"Résultat pour {uploaded_file.name} : {result.upper()}") | |
| os.makedirs("fertile", exist_ok=True) | |
| os.makedirs("non_fertile", exist_ok=True) | |
| unique_filename = f"{uuid.uuid4().hex}.jpg" | |
| save_path = os.path.join(result, unique_filename) | |
| image.save(save_path) | |
| st.info(f"📁 Image sauvegardée dans le dossier : `{result}/`") | |