Spaces:
Sleeping
Sleeping
wip
Browse files
app.py
CHANGED
|
@@ -3,12 +3,15 @@ import requests
|
|
| 3 |
from PIL import Image
|
| 4 |
from io import BytesIO
|
| 5 |
|
| 6 |
-
# Configuration de l'API Hugging Face
|
| 7 |
-
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
if response.status_code == 200:
|
| 13 |
return response.content
|
| 14 |
else:
|
|
@@ -16,20 +19,26 @@ def generate_image(prompt):
|
|
| 16 |
return None
|
| 17 |
|
| 18 |
def main():
|
| 19 |
-
st.title("Générateur de photo de profil LinkedIn")
|
| 20 |
|
| 21 |
prompt = st.text_input(
|
| 22 |
"Entrez une description pour générer une image :",
|
| 23 |
"A professional LinkedIn profile picture of a person in business attire, standing in a well-lit office environment with a neutral background."
|
| 24 |
)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
main()
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
from io import BytesIO
|
| 5 |
|
| 6 |
+
# Configuration de l'API Hugging Face (Inpainting model)
|
| 7 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-inpainting"
|
| 8 |
|
| 9 |
+
def generate_image_with_face(image, prompt):
|
| 10 |
+
response = requests.post(
|
| 11 |
+
API_URL,
|
| 12 |
+
files={"file": image}, # Utiliser l'image uploadée pour inpainting
|
| 13 |
+
data={"inputs": prompt}
|
| 14 |
+
)
|
| 15 |
if response.status_code == 200:
|
| 16 |
return response.content
|
| 17 |
else:
|
|
|
|
| 19 |
return None
|
| 20 |
|
| 21 |
def main():
|
| 22 |
+
st.title("Générateur de photo de profil LinkedIn avec votre propre visage")
|
| 23 |
|
| 24 |
prompt = st.text_input(
|
| 25 |
"Entrez une description pour générer une image :",
|
| 26 |
"A professional LinkedIn profile picture of a person in business attire, standing in a well-lit office environment with a neutral background."
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# Télécharger la photo de l'utilisateur
|
| 30 |
+
uploaded_image = st.file_uploader("Téléchargez une photo de votre visage (JPEG/PNG)", type=["jpg", "jpeg", "png"])
|
| 31 |
+
|
| 32 |
+
if uploaded_image is not None:
|
| 33 |
+
st.image(uploaded_image, caption="Votre photo téléchargée", use_column_width=True)
|
| 34 |
+
|
| 35 |
+
if st.button("Générer l'image avec votre visage"):
|
| 36 |
+
image_data = generate_image_with_face(uploaded_image, prompt)
|
| 37 |
+
if image_data:
|
| 38 |
+
generated_image = Image.open(BytesIO(image_data))
|
| 39 |
+
st.image(generated_image, caption="Image générée avec votre visage", use_column_width=True)
|
| 40 |
+
else:
|
| 41 |
+
st.error("Une erreur est survenue lors de la génération de l'image.")
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
main()
|