Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
from PIL import Image, ImageDraw
|
| 5 |
+
|
| 6 |
+
# Fonction pour générer une image simple et stylisée d'un animal
|
| 7 |
+
def generate_animal_image(animal):
|
| 8 |
+
img_size = (300, 300)
|
| 9 |
+
image = Image.new("RGB", img_size, (255, 255, 255))
|
| 10 |
+
draw = ImageDraw.Draw(image)
|
| 11 |
+
|
| 12 |
+
# Paramètres pour dessiner chaque animal
|
| 13 |
+
if animal == "Chat":
|
| 14 |
+
# Corps du chat (cercle simple + oreilles)
|
| 15 |
+
draw.ellipse((50, 100, 250, 300), fill=(200, 160, 200), outline="black")
|
| 16 |
+
draw.polygon([(80, 100), (100, 60), (120, 100)], fill=(200, 160, 200), outline="black") # Oreille gauche
|
| 17 |
+
draw.polygon([(180, 100), (200, 60), (220, 100)], fill=(200, 160, 200), outline="black") # Oreille droite
|
| 18 |
+
|
| 19 |
+
elif animal == "Chien":
|
| 20 |
+
# Corps du chien (forme ovale + oreilles pendantes)
|
| 21 |
+
draw.ellipse((50, 100, 250, 300), fill=(160, 100, 60), outline="black")
|
| 22 |
+
draw.rectangle([(60, 60), (100, 120)], fill=(160, 100, 60), outline="black") # Oreille gauche
|
| 23 |
+
draw.rectangle([(200, 60), (240, 120)], fill=(160, 100, 60), outline="black") # Oreille droite
|
| 24 |
+
|
| 25 |
+
elif animal == "Cheval":
|
| 26 |
+
# Corps du cheval (corps allongé + oreilles en pointe)
|
| 27 |
+
draw.rectangle([(80, 150), (220, 300)], fill=(120, 70, 50), outline="black")
|
| 28 |
+
draw.polygon([(100, 150), (110, 100), (130, 150)], fill=(120, 70, 50), outline="black") # Oreille gauche
|
| 29 |
+
draw.polygon([(170, 150), (180, 100), (200, 150)], fill=(120, 70, 50), outline="black") # Oreille droite
|
| 30 |
+
|
| 31 |
+
return image
|
| 32 |
+
|
| 33 |
+
# Initialisation de l'interface Streamlit
|
| 34 |
+
st.title("Générateur d'Images d'Animaux")
|
| 35 |
+
|
| 36 |
+
# Variables de session pour stocker l'état des images générées
|
| 37 |
+
if "animal_image" not in st.session_state:
|
| 38 |
+
st.session_state.animal_image = None
|
| 39 |
+
|
| 40 |
+
# Boutons pour sélectionner l'animal
|
| 41 |
+
col1, col2, col3 = st.columns(3)
|
| 42 |
+
with col1:
|
| 43 |
+
if st.button("Chat"):
|
| 44 |
+
st.session_state.animal_image = generate_animal_image("Chat")
|
| 45 |
+
|
| 46 |
+
with col2:
|
| 47 |
+
if st.button("Chien"):
|
| 48 |
+
st.session_state.animal_image = generate_animal_image("Chien")
|
| 49 |
+
|
| 50 |
+
with col3:
|
| 51 |
+
if st.button("Cheval"):
|
| 52 |
+
st.session_state.animal_image = generate_animal_image("Cheval")
|
| 53 |
+
|
| 54 |
+
# Affichage de l'image générée
|
| 55 |
+
if st.session_state.animal_image:
|
| 56 |
+
st.image(st.session_state.animal_image, caption="Image Générée", use_column_width=False, width=300)
|
| 57 |
+
|
| 58 |
+
# Bouton de réinitialisation
|
| 59 |
+
if st.button("Réinitialiser", key="reset", help="Cliquez pour générer une nouvelle image"):
|
| 60 |
+
st.session_state.animal_image = None
|