Spaces:
Sleeping
Sleeping
feat: Add more templates (#14)
Browse files- feat: Add more templates (82e52844617435e1ce20194ca796650f9b058b05)
- .gitattributes +3 -0
- app.py +8 -2
- assets/template_c_natura.png +3 -0
- assets/template_c_outros.png +3 -0
- assets/template_c_outros_sem_cupom.png +3 -0
- template_system.py +88 -3
.gitattributes
CHANGED
|
@@ -40,3 +40,6 @@ assets/template_1.png filter=lfs diff=lfs merge=lfs -text
|
|
| 40 |
assets/template_2.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
assets/template_b_avon.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
assets/template_b_natura.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
assets/template_2.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
assets/template_b_avon.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
assets/template_b_natura.png filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
assets/template_c_natura.png filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
assets/template_c_outros_sem_cupom.png filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
assets/template_c_outros.png filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -133,8 +133,14 @@ with gr.Blocks() as demo:
|
|
| 133 |
image_final_price_input = gr.Number(label="Final Price", placeholder="Enter final price...")
|
| 134 |
image_coupon_code_input = gr.Textbox(label="Coupon Code", placeholder="Enter coupon code...")
|
| 135 |
template_selection = gr.Radio(
|
| 136 |
-
choices=[
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
label="Template Selection"
|
| 139 |
)
|
| 140 |
gen_image_btn = gr.Button("Generate Image")
|
|
|
|
| 133 |
image_final_price_input = gr.Number(label="Final Price", placeholder="Enter final price...")
|
| 134 |
image_coupon_code_input = gr.Textbox(label="Coupon Code", placeholder="Enter coupon code...")
|
| 135 |
template_selection = gr.Radio(
|
| 136 |
+
choices=[
|
| 137 |
+
"outros",
|
| 138 |
+
"outros_sem_cupom",
|
| 139 |
+
"natura",
|
| 140 |
+
"avon",
|
| 141 |
+
"lidi_promo",
|
| 142 |
+
"natura_cliente"],
|
| 143 |
+
value="outros",
|
| 144 |
label="Template Selection"
|
| 145 |
)
|
| 146 |
gen_image_btn = gr.Button("Generate Image")
|
assets/template_c_natura.png
ADDED
|
Git LFS Details
|
assets/template_c_outros.png
ADDED
|
Git LFS Details
|
assets/template_c_outros_sem_cupom.png
ADDED
|
Git LFS Details
|
template_system.py
CHANGED
|
@@ -219,7 +219,7 @@ class LidiPromoTemplate(Template):
|
|
| 219 |
}
|
| 220 |
|
| 221 |
|
| 222 |
-
class
|
| 223 |
"""
|
| 224 |
Template implementation for Natura promotional images.
|
| 225 |
Uses template_b_natura.png with different configuration.
|
|
@@ -353,7 +353,92 @@ class AvonTemplate(Template):
|
|
| 353 |
}
|
| 354 |
|
| 355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
# Register additional templates
|
| 357 |
TemplateRegistry.register('lidi_promo', LidiPromoTemplate)
|
| 358 |
-
TemplateRegistry.register('natura',
|
| 359 |
-
TemplateRegistry.register('avon', AvonTemplate)
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
}
|
| 220 |
|
| 221 |
|
| 222 |
+
class NaturaClienteTemplate(Template):
|
| 223 |
"""
|
| 224 |
Template implementation for Natura promotional images.
|
| 225 |
Uses template_b_natura.png with different configuration.
|
|
|
|
| 353 |
}
|
| 354 |
|
| 355 |
|
| 356 |
+
class TemplateC(Template):
|
| 357 |
+
"""
|
| 358 |
+
Template implementation for Avon promotional images.
|
| 359 |
+
Uses template_b_avon.png with Avon-specific configuration.
|
| 360 |
+
"""
|
| 361 |
+
|
| 362 |
+
def __init__(self, template_path: str):
|
| 363 |
+
super().__init__(template_path)
|
| 364 |
+
|
| 365 |
+
def get_box_config(self) -> Dict[str, Any]:
|
| 366 |
+
"""Return box configuration for product image."""
|
| 367 |
+
return {
|
| 368 |
+
'size': (602, 434),
|
| 369 |
+
'position': (54, 304) # (x, y) from top-left corner
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
def get_text_config(self) -> Dict[str, Dict[str, Any]]:
|
| 373 |
+
"""Return text configuration for all text elements."""
|
| 374 |
+
return {
|
| 375 |
+
'product_name': {
|
| 376 |
+
'position': (72, 777),
|
| 377 |
+
'color': '#000000',
|
| 378 |
+
'font': 'font_name',
|
| 379 |
+
'anchor': 'ls'
|
| 380 |
+
},
|
| 381 |
+
'original_price': {
|
| 382 |
+
'position': (72, 815),
|
| 383 |
+
'color': '#666666',
|
| 384 |
+
'font': 'font_price_from',
|
| 385 |
+
'anchor': 'ls'
|
| 386 |
+
},
|
| 387 |
+
'final_price': {
|
| 388 |
+
'position': (90, 887),
|
| 389 |
+
'color': '#FFFFFF',
|
| 390 |
+
'font': 'font_price',
|
| 391 |
+
'anchor': 'lm'
|
| 392 |
+
},
|
| 393 |
+
'coupon_code': {
|
| 394 |
+
'position': (471, 1020),
|
| 395 |
+
'color': '#FFFFFF',
|
| 396 |
+
'font': 'font_cupom',
|
| 397 |
+
'anchor': 'ms'
|
| 398 |
+
}
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
def get_font_config(self) -> Dict[str, Dict[str, Any]]:
|
| 402 |
+
"""Return font configuration for different text elements."""
|
| 403 |
+
return {
|
| 404 |
+
'font_name': {
|
| 405 |
+
'path': 'assets/Montserrat-Bold.ttf',
|
| 406 |
+
'size': 32
|
| 407 |
+
},
|
| 408 |
+
'font_price_from': {
|
| 409 |
+
'path': 'assets/Montserrat-Regular.ttf',
|
| 410 |
+
'size': 22
|
| 411 |
+
},
|
| 412 |
+
'font_price': {
|
| 413 |
+
'path': 'assets/Montserrat-Bold.ttf',
|
| 414 |
+
'size': 40
|
| 415 |
+
},
|
| 416 |
+
'font_cupom': {
|
| 417 |
+
'path': 'assets/Montserrat-Bold.ttf',
|
| 418 |
+
'size': 42
|
| 419 |
+
}
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
class TemplateOutros(TemplateC):
|
| 424 |
+
|
| 425 |
+
def __init__(self, template_path: str = None):
|
| 426 |
+
super().__init__("assets/template_c_outros.png")
|
| 427 |
+
|
| 428 |
+
class TemplateOutrosSemCupom(TemplateC):
|
| 429 |
+
|
| 430 |
+
def __init__(self, template_path: str = None):
|
| 431 |
+
super().__init__("assets/template_c_outros_sem_cupom.png")
|
| 432 |
+
|
| 433 |
+
class TemplateNatura(TemplateC):
|
| 434 |
+
|
| 435 |
+
def __init__(self, template_path: str = None):
|
| 436 |
+
super().__init__("assets/template_c_natura.png")
|
| 437 |
+
|
| 438 |
# Register additional templates
|
| 439 |
TemplateRegistry.register('lidi_promo', LidiPromoTemplate)
|
| 440 |
+
TemplateRegistry.register('natura', TemplateNatura)
|
| 441 |
+
TemplateRegistry.register('avon', AvonTemplate)
|
| 442 |
+
TemplateRegistry.register('outros', TemplateOutros)
|
| 443 |
+
TemplateRegistry.register('outros_sem_cupom', TemplateOutrosSemCupom)
|
| 444 |
+
TemplateRegistry.register('natura_cliente', NaturaClienteTemplate)
|