Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 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
|
|
|
|
| 8 |
|
| 9 |
# Styles disponibles
|
| 10 |
STYLES = {
|
|
@@ -38,40 +37,16 @@ PROMPT_SUGGESTIONS = {
|
|
| 38 |
]
|
| 39 |
}
|
| 40 |
|
| 41 |
-
def
|
| 42 |
"""
|
| 43 |
-
|
| 44 |
"""
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 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 |
"""
|
|
@@ -86,7 +61,7 @@ def get_example_prompt(style):
|
|
| 86 |
suggestions = PROMPT_SUGGESTIONS.get(style, [])
|
| 87 |
return random.choice(suggestions) if suggestions else ""
|
| 88 |
|
| 89 |
-
with gr.Blocks(
|
| 90 |
gr.Markdown(
|
| 91 |
"""
|
| 92 |
# 🎨 Equity Creation Studio
|
|
@@ -157,7 +132,7 @@ with gr.Blocks(css="footer {display: none}") as demo:
|
|
| 157 |
)
|
| 158 |
|
| 159 |
generate_btn.click(
|
| 160 |
-
fn=
|
| 161 |
inputs=[prompt, style, format_size, material],
|
| 162 |
outputs=[output]
|
| 163 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
import time
|
|
|
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
+
import requests
|
| 6 |
+
from io import BytesIO
|
| 7 |
|
| 8 |
# Styles disponibles
|
| 9 |
STYLES = {
|
|
|
|
| 37 |
]
|
| 38 |
}
|
| 39 |
|
| 40 |
+
def generate_test_image(prompt, style, format_size, material):
|
| 41 |
"""
|
| 42 |
+
Fonction de simulation de génération d'image
|
| 43 |
"""
|
| 44 |
+
# Simuler un délai de génération
|
| 45 |
+
time.sleep(2)
|
| 46 |
+
|
| 47 |
+
# Pour le moment, retourner une image de test
|
| 48 |
+
test_image = Image.new('RGB', (512, 512), color = 'white')
|
| 49 |
+
return test_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
def update_suggestions(style):
|
| 52 |
"""
|
|
|
|
| 61 |
suggestions = PROMPT_SUGGESTIONS.get(style, [])
|
| 62 |
return random.choice(suggestions) if suggestions else ""
|
| 63 |
|
| 64 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 65 |
gr.Markdown(
|
| 66 |
"""
|
| 67 |
# 🎨 Equity Creation Studio
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
generate_btn.click(
|
| 135 |
+
fn=generate_test_image,
|
| 136 |
inputs=[prompt, style, format_size, material],
|
| 137 |
outputs=[output]
|
| 138 |
)
|