Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,65 +1,50 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Interface Streamlit
|
| 25 |
-
st.title("Générateur d'
|
| 26 |
-
|
| 27 |
-
# Boutons d'animaux
|
| 28 |
-
animal = st.radio("Choisissez un animal", ["Chat", "Chien", "Cheval"])
|
| 29 |
-
|
| 30 |
-
# Génération d'une "image" aléatoire chaque 3 secondes (sans API ni stockage d'image)
|
| 31 |
-
if st.session_state["auto_run"]:
|
| 32 |
-
image_data = generate_random_image_data()
|
| 33 |
-
st.image(image_data, caption=f"Image générée pour {animal}", use_column_width=True)
|
| 34 |
-
|
| 35 |
-
# Extraction de "caractéristiques" de l'image (simulation)
|
| 36 |
-
feature_description = extract_image_features(image_data)
|
| 37 |
-
st.write("Caractéristiques extraites de l'image :")
|
| 38 |
-
st.write(feature_description)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
col1, col2 = st.columns(2)
|
| 42 |
-
if col1.button("Oui"):
|
| 43 |
-
st.session_state["feedback"].append({"animal": animal, "features": feature_description})
|
| 44 |
-
st.write("Feedback positif enregistré.")
|
| 45 |
-
elif col2.button("Non"):
|
| 46 |
-
st.write("Feedback négatif : L'image ne correspond pas.")
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
don_data = st.text_area("Entrez les données manuellement", value=st.session_state["don_data"])
|
| 57 |
-
if st.form_submit_button("Envoyer"):
|
| 58 |
-
st.session_state["don_data"] = don_data
|
| 59 |
-
st.write("Données ajoutées avec succès.")
|
| 60 |
-
st.session_state["auto_run"] = False # Arrête l'auto-génération si le don est activé
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
if st.
|
| 64 |
-
|
| 65 |
-
st.experimental_rerun()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import requests
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
# Initialisation des données
|
| 8 |
+
if "images" not in st.session_state:
|
| 9 |
+
st.session_state.images = []
|
| 10 |
+
|
| 11 |
+
# Téléchargement d'images basiques selon le bouton cliqué
|
| 12 |
+
def download_image(animal):
|
| 13 |
+
url = {
|
| 14 |
+
"Chat": "https://i.ibb.co/2FnDthw/IMG-6419.jpg", # Lien mis à jour pour le chat
|
| 15 |
+
"Chien": "https://example.com/sample-dog-image.jpg",
|
| 16 |
+
"Cheval": "https://example.com/sample-horse-image.jpg"
|
| 17 |
+
}.get(animal, None)
|
| 18 |
+
if url:
|
| 19 |
+
response = requests.get(url)
|
| 20 |
+
img = Image.open(BytesIO(response.content)).resize((300, 300))
|
| 21 |
+
st.session_state.images.append(img)
|
| 22 |
+
analyze_image(img)
|
| 23 |
+
|
| 24 |
+
# Analyse basique de l'image
|
| 25 |
+
def analyze_image(img):
|
| 26 |
+
st.write("Analyse basique de l'image")
|
| 27 |
+
arr = np.array(img)
|
| 28 |
+
avg_color = arr.mean(axis=(0, 1))
|
| 29 |
+
st.write(f"Couleur moyenne: {avg_color}")
|
| 30 |
|
| 31 |
# Interface Streamlit
|
| 32 |
+
st.title("Générateur d'Images Auto-Entrant (Démonstration)")
|
| 33 |
+
st.write("Choisissez un animal pour générer une image et analyser ses pixels.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
col1, col2, col3 = st.columns(3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
if col1.button("Chat"):
|
| 38 |
+
download_image("Chat")
|
| 39 |
+
if col2.button("Chien"):
|
| 40 |
+
download_image("Chien")
|
| 41 |
+
if col3.button("Cheval"):
|
| 42 |
+
download_image("Cheval")
|
| 43 |
|
| 44 |
+
# Affichage des images et analyses
|
| 45 |
+
for idx, img in enumerate(st.session_state.images):
|
| 46 |
+
st.image(img, caption=f"Image {idx+1}", width=300)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
# Bouton pour réinitialiser
|
| 49 |
+
if st.button("Redémarrer", key="reset"):
|
| 50 |
+
st.session_state.images = []
|
|
|