File size: 10,990 Bytes
c290e43 f29baad 8d16bbc c290e43 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc f29baad 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc f29baad 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 a348baa 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc a348baa 5759851 8d16bbc 5759851 8d16bbc c290e43 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 5759851 8d16bbc 4390781 8d16bbc c290e43 8d16bbc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
import gradio as gr
import os
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
import requests
import io
import json
# Styles artistiques professionnels inspirés des meilleurs designers
PRO_STYLES = {
"Neo Vintage": {
"prompt_prefix": "professional high-end vintage poster, screen printing style, halftone textures, limited color palette",
"guidance": 13.5,
"steps": 75,
"negative": "photorealistic, 3d, oversaturated, amateur",
"reference": "modern vintage illustration masters"
},
"Art Contemporain": {
"prompt_prefix": "contemporary art poster, bold artistic composition, professional design, gallery quality",
"guidance": 12.5,
"steps": 70,
"negative": "basic, simple, childish",
"reference": "modern art gallery style"
},
"Illustration Éditoriale": {
"prompt_prefix": "professional editorial illustration, sophisticated art style, magazine quality",
"guidance": 14.0,
"steps": 80,
"negative": "basic drawing, sketchy, unrefined",
"reference": "high-end magazine art"
},
"Design Minimaliste Plus": {
"prompt_prefix": "premium minimalist design, refined composition, luxury poster style",
"guidance": 11.5,
"steps": 65,
"negative": "cluttered, busy, complex",
"reference": "scandinavian design principles"
}
}
# Collections artistiques spécialisées
ARTISTIC_COLLECTIONS = {
"Portraits Animaliers Pro": {
"base_prompts": [
"majestic animal portrait",
"artistic wildlife illustration",
"powerful animal character"
],
"style_elements": [
"dramatic lighting",
"expressive eyes",
"detailed textures",
"strong personality"
],
"negative": "cute, cartoon, realistic photo",
"compositions": [
"centered portrait",
"dramatic angle",
"close-up detail"
]
},
"Nature Graphique": {
"base_prompts": [
"graphic botanical art",
"stylized nature elements",
"organic patterns"
],
"style_elements": [
"decorative details",
"flowing lines",
"dynamic composition"
],
"negative": "photographic, plain, realistic",
"compositions": [
"geometric arrangement",
"pattern layout",
"abstract interpretation"
]
},
"Urban Art Plus": {
"base_prompts": [
"sophisticated urban art",
"street art fusion",
"modern city aesthetic"
],
"style_elements": [
"street art textures",
"urban patterns",
"graffiti elements"
],
"negative": "amateur graffiti, messy, unrefined",
"compositions": [
"dynamic urban composition",
"street art layout",
"modern city vibes"
]
}
}
# Formats professionnels optimisés
PRO_DIMENSIONS = {
"A4+": (1152, 1634), # Optimisé pour qualité pro
"A3+": (1634, 2314),
"A2+": (2314, 3271),
"A1+": (3271, 4628),
"A0+": (4628, 6544)
}
class EquityArtisanPro:
def __init__(self):
self.model_url = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
self.headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_TOKEN')}"}
def generate_artwork(self, format_size, orientation, style, collection, prompt, quality, creativity):
try:
# Configuration des dimensions
width, height = PRO_DIMENSIONS[format_size]
if orientation == "Paysage":
width, height = height, width
# Construction du prompt artistique
style_config = PRO_STYLES[style]
collection_config = ARTISTIC_COLLECTIONS.get(collection)
# Prompt engineering avancé
enhanced_prompt = self._build_enhanced_prompt(
base_prompt=prompt,
style_config=style_config,
collection_config=collection_config
)
# Configuration avancée
payload = {
"inputs": enhanced_prompt,
"parameters": {
"negative_prompt": self._build_negative_prompt(style_config, collection_config),
"num_inference_steps": self._calculate_steps(style_config, quality),
"guidance_scale": self._calculate_guidance(style_config, creativity),
"width": width,
"height": height,
"seed": int(creativity * 1000) # Contrôle créatif
}
}
print(f"Generating with enhanced prompt: {enhanced_prompt[:100]}...")
response = requests.post(
self.model_url,
headers=self.headers,
json=payload,
timeout=60
)
if response.status_code == 200:
image = Image.open(io.BytesIO(response.content))
image = self._post_process_image(image, quality)
return image, "✨ Chef d'œuvre créé avec succès!"
else:
return None, f"⚠️ Erreur {response.status_code}: {response.text}"
except Exception as e:
print(f"Error: {str(e)}")
return None, f"⚠️ Erreur: {str(e)}"
def _build_enhanced_prompt(self, base_prompt, style_config, collection_config=None):
prompt_parts = [
style_config["prompt_prefix"],
base_prompt
]
if collection_config:
prompt_parts.extend([
f"in style of {', '.join(collection_config['style_elements'])}",
f"with {', '.join(collection_config['base_prompts'])}",
f"featuring {', '.join(collection_config['compositions'])}"
])
return ", ".join(prompt_parts) + ", professional poster design, masterpiece quality"
def _build_negative_prompt(self, style_config, collection_config=None):
negative_parts = [
style_config["negative"],
"poor quality, amateur design, basic composition"
]
if collection_config:
negative_parts.append(collection_config["negative"])
return ", ".join(negative_parts)
def _calculate_steps(self, style_config, quality):
base_steps = style_config["steps"]
return int(base_steps * (quality/85)) # Scaled by quality
def _calculate_guidance(self, style_config, creativity):
base_guidance = style_config["guidance"]
return base_guidance * (creativity/10) # Scaled by creativity
def _post_process_image(self, image, quality):
if quality > 85:
enhancer = ImageEnhance.Contrast(image)
image = enhancer.enhance(1.2)
enhancer = ImageEnhance.Sharpness(image)
image = enhancer.enhance(1.3)
return image
def create_interface():
artisan = EquityArtisanPro()
with gr.Blocks(theme=gr.themes.Soft(
primary_hue="indigo",
secondary_hue="purple",
)) as app:
gr.HTML("""
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%); border-radius: 16px; margin-bottom: 24px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);">
<h1 style="color: white; font-size: 2.5em; margin-bottom: 10px;">🎨 Equity Artisan 3.0</h1>
<p style="color: #E5E7EB; font-size: 1.2em;">Créez des œuvres d'art uniques avec notre IA spécialisée</p>
</div>
""")
with gr.Row():
# Panneau de contrôle
with gr.Column(scale=1):
with gr.Group():
gr.Markdown("### 📐 Format & Style")
format_choice = gr.Dropdown(
choices=list(PRO_DIMENSIONS.keys()),
value="A4+",
label="Format",
info="Formats optimisés pour qualité professionnelle"
)
orientation = gr.Radio(
choices=["Portrait", "Paysage"],
value="Portrait",
label="Orientation"
)
style = gr.Dropdown(
choices=list(PRO_STYLES.keys()),
value="Neo Vintage",
label="Style Artistique",
info="Styles inspirés des grands maîtres"
)
with gr.Group():
gr.Markdown("### 🎨 Vision Artistique")
collection = gr.Dropdown(
choices=list(ARTISTIC_COLLECTIONS.keys()),
label="Collection",
info="Thèmes artistiques spécialisés"
)
prompt = gr.Textbox(
lines=3,
label="Description",
placeholder="Décrivez votre vision artistique...",
info="Soyez précis et créatif"
)
with gr.Group():
gr.Markdown("### ✨ Paramètres Créatifs")
quality = gr.Slider(
minimum=70,
maximum=100,
value=85,
label="Qualité Artistique",
info="Influence la finesse des détails"
)
creativity = gr.Slider(
minimum=7,
maximum=15,
value=10,
label="Expression Créative",
info="Balance entre fidélité et originalité"
)
generate_btn = gr.Button("✨ Créer", variant="primary", scale=1)
# Zone de prévisualisation
with gr.Column(scale=2):
image_output = gr.Image(
label="Votre Création",
type="pil"
)
status = gr.Textbox(
label="Statut",
interactive=False
)
# Événements
generate_btn.click(
artisan.generate_artwork,
inputs=[
format_choice,
orientation,
style,
collection,
prompt,
quality,
creativity
],
outputs=[image_output, status]
)
return app
if __name__ == "__main__":
app = create_interface()
app.launch() |