Equityone commited on
Commit
4754e9f
·
verified ·
1 Parent(s): df2abe8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -2
app.py CHANGED
@@ -170,9 +170,32 @@ class TextRenderer:
170
  """Gestionnaire avancé de rendu de texte"""
171
 
172
  def __init__(self):
173
- self.available_fonts = self._load_fonts()
 
174
 
175
- def render_text(self, image: Image.Image, text: str, effect: str, position: Tuple[int, int]) -> Image.Image:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  """Application d'effets de texte avancés"""
177
  effect_params = TEXT_EFFECTS[effect]
178
 
@@ -200,6 +223,14 @@ class TextRenderer:
200
 
201
  class EquityArtEngine:
202
  """Moteur principal de génération artistique"""
 
 
 
 
 
 
 
 
203
 
204
  def __init__(self):
205
  self.image_processor = ImageProcessor()
 
170
  """Gestionnaire avancé de rendu de texte"""
171
 
172
  def __init__(self):
173
+ self.default_font = ImageFont.load_default()
174
+ self.fonts = self._initialize_fonts()
175
 
176
+ def _initialize_fonts(self) -> Dict[str, ImageFont.FreeTypeFont]:
177
+ """Initialise les polices disponibles"""
178
+ fonts = {
179
+ "default": self.default_font,
180
+ }
181
+
182
+ # Tentative de chargement des polices système courantes
183
+ common_fonts = {
184
+ "arial": "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
185
+ "times": "/usr/share/fonts/truetype/liberation/LiberationSerif-Regular.ttf",
186
+ "courier": "/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf"
187
+ }
188
+
189
+ for name, path in common_fonts.items():
190
+ try:
191
+ fonts[name] = ImageFont.truetype(path, size=40)
192
+ except OSError:
193
+ logger.warning(f"Police {name} non trouvée, utilisation police par défaut")
194
+ fonts[name] = self.default_font
195
+
196
+ return fonts
197
+
198
+ def render_text(self, image: Image.Image, text: str, effect: str, position: Tuple[int, int], font_name: str = "default") -> Image.Image:
199
  """Application d'effets de texte avancés"""
200
  effect_params = TEXT_EFFECTS[effect]
201
 
 
223
 
224
  class EquityArtEngine:
225
  """Moteur principal de génération artistique"""
226
+ def __init__(self):
227
+ self.image_processor = ImageProcessor()
228
+ self.text_renderer = TextRenderer()
229
+ self.model_url = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
230
+ token = os.getenv('HUGGINGFACE_TOKEN')
231
+ if not token:
232
+ logger.error("HUGGINGFACE_TOKEN non trouvé!")
233
+ self.headers = {"Authorization": f"Bearer {token}"}
234
 
235
  def __init__(self):
236
  self.image_processor = ImageProcessor()