Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,8 @@ import requests
|
|
5 |
from io import BytesIO
|
6 |
import os
|
7 |
|
8 |
-
# Token Hugging Face
|
9 |
-
HF_TOKEN = "hf_..." #
|
10 |
|
11 |
# Styles disponibles
|
12 |
STYLES = {
|
@@ -47,17 +47,15 @@ def generate_image(prompt, style, format_size, material):
|
|
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}")
|
61 |
|
62 |
payload = {
|
63 |
"inputs": enhanced_prompt,
|
@@ -69,21 +67,25 @@ def generate_image(prompt, style, format_size, material):
|
|
69 |
}
|
70 |
|
71 |
try:
|
72 |
-
print("Envoi de la requête à l'API...")
|
73 |
response = requests.post(API_URL, headers=headers, json=payload)
|
74 |
-
print(f"Status code: {response.status_code}")
|
75 |
|
76 |
if response.status_code == 200:
|
|
|
77 |
return Image.open(BytesIO(response.content))
|
78 |
else:
|
79 |
-
print(f"Erreur API - Response: {response.text}")
|
80 |
-
error_image = Image.new('RGB', (512, 512), color='
|
81 |
-
# Ajouter un message d'erreur sur l'image
|
82 |
return error_image
|
83 |
|
|
|
|
|
|
|
|
|
84 |
except Exception as e:
|
85 |
-
print(f"Exception
|
86 |
-
error_image = Image.new('RGB', (512, 512), color='
|
87 |
return error_image
|
88 |
|
89 |
def update_suggestions(style):
|
|
|
5 |
from io import BytesIO
|
6 |
import os
|
7 |
|
8 |
+
# Token Hugging Face
|
9 |
+
HF_TOKEN = "hf_..." # Assurez-vous que ce token est correct
|
10 |
|
11 |
# Styles disponibles
|
12 |
STYLES = {
|
|
|
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 = {
|
51 |
"signage": "professional signage design, minimalist, clean, photorealistic",
|
52 |
"poster": "artistic poster design, creative, expressive, highly detailed",
|
53 |
"silhouette": "decorative silhouette, elegant cutout design, clear shape"
|
54 |
}
|
55 |
|
|
|
56 |
enhanced_prompt = f"a {material} cardboard {style} design showing {prompt}, {style_prompts[style]}, professional photography, 8k uhd, detailed"
|
57 |
|
58 |
+
print(f"Envoi du prompt: {enhanced_prompt}")
|
59 |
|
60 |
payload = {
|
61 |
"inputs": enhanced_prompt,
|
|
|
67 |
}
|
68 |
|
69 |
try:
|
70 |
+
print("Envoi de la requête à l'API...")
|
71 |
response = requests.post(API_URL, headers=headers, json=payload)
|
72 |
+
print(f"Status code: {response.status_code}")
|
73 |
|
74 |
if response.status_code == 200:
|
75 |
+
print("Image générée avec succès")
|
76 |
return Image.open(BytesIO(response.content))
|
77 |
else:
|
78 |
+
print(f"Erreur API - Response: {response.text}")
|
79 |
+
error_image = Image.new('RGB', (512, 512), color='red')
|
|
|
80 |
return error_image
|
81 |
|
82 |
+
except requests.exceptions.RequestException as e:
|
83 |
+
print(f"Erreur de requête : {str(e)}")
|
84 |
+
error_image = Image.new('RGB', (512, 512), color='orange')
|
85 |
+
return error_image
|
86 |
except Exception as e:
|
87 |
+
print(f"Exception inattendue : {str(e)}")
|
88 |
+
error_image = Image.new('RGB', (512, 512), color='yellow')
|
89 |
return error_image
|
90 |
|
91 |
def update_suggestions(style):
|