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 = {
|
@@ -62,8 +62,8 @@ def generate_image(prompt, style, format_size, material):
|
|
62 |
"negative_prompt": "low quality, blurry, bad anatomy, distorted, disfigured, pixelated",
|
63 |
"num_inference_steps": 40,
|
64 |
"guidance_scale": 7.5,
|
65 |
-
"width":
|
66 |
-
"height":
|
67 |
}
|
68 |
|
69 |
try:
|
@@ -76,17 +76,20 @@ def generate_image(prompt, style, format_size, material):
|
|
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):
|
92 |
"""
|
|
|
5 |
from io import BytesIO
|
6 |
import os
|
7 |
|
8 |
+
# Token Hugging Face - Assurez-vous que ce token est correct et a les bonnes permissions
|
9 |
+
HF_TOKEN = "hf_..." # Remplacez par votre vrai token
|
10 |
|
11 |
# Styles disponibles
|
12 |
STYLES = {
|
|
|
62 |
"negative_prompt": "low quality, blurry, bad anatomy, distorted, disfigured, pixelated",
|
63 |
"num_inference_steps": 40,
|
64 |
"guidance_scale": 7.5,
|
65 |
+
"width": 512,
|
66 |
+
"height": 512
|
67 |
}
|
68 |
|
69 |
try:
|
|
|
76 |
return Image.open(BytesIO(response.content))
|
77 |
else:
|
78 |
print(f"Erreur API - Response: {response.text}")
|
79 |
+
error_message = f"Erreur {response.status_code}: {response.text}"
|
80 |
error_image = Image.new('RGB', (512, 512), color='red')
|
81 |
+
return gr.Image.update(value=error_image, label=error_message)
|
82 |
|
83 |
except requests.exceptions.RequestException as e:
|
84 |
print(f"Erreur de requête : {str(e)}")
|
85 |
+
error_message = f"Erreur de requête : {str(e)}"
|
86 |
error_image = Image.new('RGB', (512, 512), color='orange')
|
87 |
+
return gr.Image.update(value=error_image, label=error_message)
|
88 |
except Exception as e:
|
89 |
print(f"Exception inattendue : {str(e)}")
|
90 |
+
error_message = f"Erreur inattendue : {str(e)}"
|
91 |
error_image = Image.new('RGB', (512, 512), color='yellow')
|
92 |
+
return gr.Image.update(value=error_image, label=error_message)
|
93 |
|
94 |
def update_suggestions(style):
|
95 |
"""
|