Equityone commited on
Commit
953bbe0
·
verified ·
1 Parent(s): 835d10e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -12
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/runwayml/stable-diffusion-v1-5"
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"{prompt}, {style_prompts[style]}, made of {material} cardboard, eco-friendly design, high quality, professional, detailed"
 
 
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
- image_bytes = response.content
69
- return Image.open(BytesIO(image_bytes))
70
  else:
71
- print(f"Erreur API : {response.status_code}")
72
- return Image.new('RGB', (512, 512), color='lightgray')
 
 
 
73
  except Exception as e:
74
- print(f"Erreur de génération : {e}")
75
- return Image.new('RGB', (512, 512), color='lightgray')
 
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
  """