Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
import time
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Styles disponibles
|
6 |
STYLES = {
|
@@ -36,13 +40,38 @@ PROMPT_SUGGESTIONS = {
|
|
36 |
|
37 |
def generate_image(prompt, style, format_size, material):
|
38 |
"""
|
39 |
-
|
40 |
"""
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
def update_suggestions(style):
|
48 |
"""
|
@@ -112,7 +141,7 @@ with gr.Blocks(css="footer {display: none}") as demo:
|
|
112 |
|
113 |
# Panneau de droite - Prévisualisation
|
114 |
with gr.Column(scale=2):
|
115 |
-
output = gr.
|
116 |
|
117 |
# Interactions
|
118 |
style.change(
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
import time
|
4 |
+
from diffusers import StableDiffusionPipeline
|
5 |
+
import torch
|
6 |
+
from PIL import Image
|
7 |
+
import io
|
8 |
|
9 |
# Styles disponibles
|
10 |
STYLES = {
|
|
|
40 |
|
41 |
def generate_image(prompt, style, format_size, material):
|
42 |
"""
|
43 |
+
Génération d'image avec Stable Diffusion
|
44 |
"""
|
45 |
+
try:
|
46 |
+
# Construction du prompt enrichi
|
47 |
+
style_prompts = {
|
48 |
+
"signage": "professional signage, eco-friendly cardboard material, minimalist design",
|
49 |
+
"poster": "artistic poster, recycled cardboard texture, creative design",
|
50 |
+
"silhouette": "decorative silhouette, cardboard cutout, elegant design"
|
51 |
+
}
|
52 |
+
|
53 |
+
# Enrichir le prompt avec le style et le matériau
|
54 |
+
enhanced_prompt = f"{prompt}, {style_prompts[style]}, {material} cardboard material, sustainable design, high quality, detailed"
|
55 |
+
|
56 |
+
# Prompts négatifs pour améliorer la qualité
|
57 |
+
negative_prompt = "low quality, blurry, bad anatomy, ugly, distorted, pixelated"
|
58 |
+
|
59 |
+
# Initialiser le pipeline
|
60 |
+
model_id = "runwayml/stable-diffusion-v1-5"
|
61 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
|
62 |
+
|
63 |
+
# Générer l'image
|
64 |
+
image = pipe(
|
65 |
+
prompt=enhanced_prompt,
|
66 |
+
negative_prompt=negative_prompt,
|
67 |
+
num_inference_steps=30,
|
68 |
+
guidance_scale=7.5
|
69 |
+
).images[0]
|
70 |
+
|
71 |
+
return image
|
72 |
+
|
73 |
+
except Exception as e:
|
74 |
+
return f"Erreur lors de la génération : {str(e)}"
|
75 |
|
76 |
def update_suggestions(style):
|
77 |
"""
|
|
|
141 |
|
142 |
# Panneau de droite - Prévisualisation
|
143 |
with gr.Column(scale=2):
|
144 |
+
output = gr.Image(label="Image générée")
|
145 |
|
146 |
# Interactions
|
147 |
style.change(
|