Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,35 +44,47 @@ def generate_image(prompt, style, format_size, material):
|
|
44 |
"""
|
45 |
Génération d'image via l'API Hugging Face
|
46 |
"""
|
47 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
48 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
49 |
|
50 |
# Style prompts pour améliorer la génération
|
51 |
style_prompts = {
|
52 |
-
"signage": "professional signage design, minimalist, clean",
|
53 |
-
"poster": "artistic poster design, creative, expressive",
|
54 |
-
"silhouette": "decorative silhouette, elegant cutout design"
|
55 |
}
|
56 |
|
57 |
# Enrichir le prompt
|
58 |
-
enhanced_prompt = f"{
|
|
|
|
|
59 |
|
60 |
payload = {
|
61 |
"inputs": enhanced_prompt,
|
62 |
-
"negative_prompt": "low quality, blurry, bad anatomy, distorted, pixelated",
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
|
65 |
try:
|
|
|
66 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
|
|
67 |
if response.status_code == 200:
|
68 |
-
|
69 |
-
return Image.open(BytesIO(image_bytes))
|
70 |
else:
|
71 |
-
print(f"Erreur API : {response.
|
72 |
-
|
|
|
|
|
|
|
73 |
except Exception as e:
|
74 |
-
print(f"
|
75 |
-
|
|
|
76 |
|
77 |
def update_suggestions(style):
|
78 |
"""
|
|
|
44 |
"""
|
45 |
Génération d'image via l'API Hugging Face
|
46 |
"""
|
47 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
48 |
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
49 |
|
50 |
# Style prompts pour améliorer la génération
|
51 |
style_prompts = {
|
52 |
+
"signage": "professional signage design, minimalist, clean, photorealistic",
|
53 |
+
"poster": "artistic poster design, creative, expressive, highly detailed",
|
54 |
+
"silhouette": "decorative silhouette, elegant cutout design, clear shape"
|
55 |
}
|
56 |
|
57 |
# Enrichir le prompt
|
58 |
+
enhanced_prompt = f"a {material} cardboard {style} design showing {prompt}, {style_prompts[style]}, professional photography, 8k uhd, detailed"
|
59 |
+
|
60 |
+
print(f"Envoi du prompt: {enhanced_prompt}") # Pour debug
|
61 |
|
62 |
payload = {
|
63 |
"inputs": enhanced_prompt,
|
64 |
+
"negative_prompt": "low quality, blurry, bad anatomy, distorted, disfigured, pixelated",
|
65 |
+
"num_inference_steps": 40,
|
66 |
+
"guidance_scale": 7.5,
|
67 |
+
"width": 768,
|
68 |
+
"height": 768
|
69 |
}
|
70 |
|
71 |
try:
|
72 |
+
print("Envoi de la requête à l'API...") # Pour debug
|
73 |
response = requests.post(API_URL, headers=headers, json=payload)
|
74 |
+
print(f"Status code: {response.status_code}") # Pour debug
|
75 |
+
|
76 |
if response.status_code == 200:
|
77 |
+
return Image.open(BytesIO(response.content))
|
|
|
78 |
else:
|
79 |
+
print(f"Erreur API - Response: {response.text}") # Pour debug
|
80 |
+
error_image = Image.new('RGB', (512, 512), color='lightgray')
|
81 |
+
# Ajouter un message d'erreur sur l'image
|
82 |
+
return error_image
|
83 |
+
|
84 |
except Exception as e:
|
85 |
+
print(f"Exception lors de la génération: {str(e)}") # Pour debug
|
86 |
+
error_image = Image.new('RGB', (512, 512), color='lightgray')
|
87 |
+
return error_image
|
88 |
|
89 |
def update_suggestions(style):
|
90 |
"""
|