Spaces:
Sleeping
Sleeping
fix: force png output
#2
by
ferrymangmi - opened
app.py
CHANGED
|
@@ -20,25 +20,35 @@ def generate_image(prompt):
|
|
| 20 |
Génère une image à partir du prompt en utilisant le modèle Hugging Face.
|
| 21 |
"""
|
| 22 |
if pipe is None:
|
| 23 |
-
|
| 24 |
|
| 25 |
try:
|
| 26 |
# Générer l'image
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
return image
|
| 30 |
|
| 31 |
except Exception as e:
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
|
| 35 |
# Interface Gradio
|
| 36 |
iface = gr.Interface(
|
| 37 |
fn=generate_image,
|
| 38 |
inputs=gr.Textbox(label="Prompt"),
|
| 39 |
-
outputs=gr.Image(label="
|
| 40 |
-
title="
|
| 41 |
-
description="
|
| 42 |
)
|
| 43 |
|
| 44 |
# Lancer l'application
|
|
|
|
| 20 |
Génère une image à partir du prompt en utilisant le modèle Hugging Face.
|
| 21 |
"""
|
| 22 |
if pipe is None:
|
| 23 |
+
raise ValueError("The model couldn't be loaded.")
|
| 24 |
|
| 25 |
try:
|
| 26 |
# Générer l'image
|
| 27 |
+
result = pipe(prompt)
|
| 28 |
+
|
| 29 |
+
# Vérifier que le résultat contient des images
|
| 30 |
+
if not hasattr(result, 'images') or len(result.images) == 0:
|
| 31 |
+
raise ValueError("The model couldn't generate an image.")
|
| 32 |
+
|
| 33 |
+
image = result.images[0]
|
| 34 |
+
|
| 35 |
+
# S'assurer que l'image est au format PIL.Image
|
| 36 |
+
if not isinstance(image, Image.Image):
|
| 37 |
+
image = Image.fromarray(image)
|
| 38 |
|
| 39 |
return image
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
+
# Lever une exception pour que Gradio puisse la gérer
|
| 43 |
+
raise ValueError(f"Erreur lors de la génération : {str(e)}")
|
| 44 |
|
| 45 |
# Interface Gradio
|
| 46 |
iface = gr.Interface(
|
| 47 |
fn=generate_image,
|
| 48 |
inputs=gr.Textbox(label="Prompt"),
|
| 49 |
+
outputs=gr.Image(label="Generated Image"),
|
| 50 |
+
title="Rick Generator",
|
| 51 |
+
description="Enter a prompt to generate an image with the Rick Generator model."
|
| 52 |
)
|
| 53 |
|
| 54 |
# Lancer l'application
|