Spaces:
Sleeping
Sleeping
wip
Browse files
app.py
CHANGED
|
@@ -6,12 +6,16 @@ from io import BytesIO
|
|
| 6 |
# Configuration de l'API Hugging Face (Inpainting model)
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
if response.status_code == 200:
|
| 16 |
return response.content
|
| 17 |
else:
|
|
@@ -33,7 +37,9 @@ def main():
|
|
| 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 |
-
|
|
|
|
|
|
|
| 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)
|
|
|
|
| 6 |
# Configuration de l'API Hugging Face (Inpainting model)
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
| 8 |
|
| 9 |
+
|
| 10 |
+
def generate_image_with_face(image_bytes, prompt):
|
| 11 |
+
# L'image est envoyée en tant que fichier binaire, pas en tant que texte
|
| 12 |
+
files = {
|
| 13 |
+
"image": ("image.png", image_bytes, "image/png"),
|
| 14 |
+
}
|
| 15 |
+
data = {"inputs": prompt}
|
| 16 |
+
|
| 17 |
+
response = requests.post(API_URL, files=files, data=data)
|
| 18 |
+
|
| 19 |
if response.status_code == 200:
|
| 20 |
return response.content
|
| 21 |
else:
|
|
|
|
| 37 |
st.image(uploaded_image, caption="Votre photo téléchargée", use_column_width=True)
|
| 38 |
|
| 39 |
if st.button("Générer l'image avec votre visage"):
|
| 40 |
+
# Lire l'image en binaire
|
| 41 |
+
image_bytes = uploaded_image.read() # Lire l'image en bytes
|
| 42 |
+
image_data = generate_image_with_face(image_bytes, prompt)
|
| 43 |
if image_data:
|
| 44 |
generated_image = Image.open(BytesIO(image_data))
|
| 45 |
st.image(generated_image, caption="Image générée avec votre visage", use_column_width=True)
|