Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# app.py - Gym Workout Plan PDF
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
from fpdf import FPDF
|
|
@@ -12,74 +12,83 @@ class GymWorkoutPDF(FPDF):
|
|
| 12 |
self.set_font('Arial', 'I', 7)
|
| 13 |
self.cell(0, 8, f'GYM WORKOUT PLAN | Page {self.page_no()} | {datetime.now().strftime("%d/%m/%Y")}', 0, 0, 'C')
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
"""
|
| 17 |
if not text:
|
| 18 |
return "Workout Plan"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
replacements = {
|
| 20 |
'โ': '-', 'โ': '-', 'โ': '"', 'โ': '"', 'โ': "'", 'โ': "'",
|
| 21 |
-
'โข': '
|
|
|
|
| 22 |
}
|
|
|
|
| 23 |
for old, new in replacements.items():
|
| 24 |
-
text =
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
def
|
| 30 |
-
# Validation
|
| 31 |
if not title.strip():
|
| 32 |
return None, "โ Workout Plan Title Required!"
|
| 33 |
|
| 34 |
names_list = [n.strip() for n in names.split(',') if n.strip()]
|
| 35 |
|
| 36 |
if not names_list:
|
| 37 |
-
return None, "โ Add Member Names!"
|
| 38 |
|
| 39 |
if len(names_list) > 30:
|
| 40 |
-
return None, "โ Max 30
|
| 41 |
|
| 42 |
if not image_files or len(names_list) != len(image_files):
|
| 43 |
return None, f"โ Need {len(names_list)} Member Photos!"
|
| 44 |
|
| 45 |
try:
|
| 46 |
pdf = GymWorkoutPDF()
|
| 47 |
-
pdf.set_margins(18, 18, 18)
|
| 48 |
pdf.set_auto_page_break(auto=True, margin=18)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
# GYM COVER PAGE (Compact)
|
| 53 |
pdf.add_page()
|
| 54 |
-
pdf.set_font('Arial', 'B',
|
| 55 |
-
pdf.set_text_color(0, 128, 0)
|
| 56 |
-
pdf.cell(0,
|
| 57 |
-
pdf.set_font('Arial', 'B', 14)
|
| 58 |
-
pdf.cell(0, 10, clean_title.upper(), ln=1, align='C')
|
| 59 |
|
| 60 |
-
pdf.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
pdf.set_font('Arial', 'B', 11)
|
| 62 |
-
pdf.cell(0, 8, f"{'='*
|
| 63 |
pdf.set_font('Arial', '', 10)
|
| 64 |
-
pdf.cell(0, 8, f"MEMBERS: {len(names_list)}", ln=1, align='C')
|
| 65 |
-
pdf.cell(0, 8, f"
|
| 66 |
pdf.set_font('Arial', 'B', 11)
|
| 67 |
-
pdf.cell(0, 8, f"{'='*
|
| 68 |
|
| 69 |
-
# MEMBER
|
| 70 |
for i, (name, img_path) in enumerate(zip(names_list, image_files)):
|
| 71 |
pdf.add_page()
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
pdf.set_font('Arial', 'B',
|
| 75 |
-
pdf.set_text_color(0, 128, 0)
|
| 76 |
-
pdf.cell(0,
|
| 77 |
|
| 78 |
-
# PHOTO SECTION (
|
| 79 |
pdf.ln(8)
|
| 80 |
-
img_width = 100
|
| 81 |
-
img_height = 120
|
| 82 |
-
page_width = pdf.w - 36
|
| 83 |
x_pos = (page_width - img_width) / 2 + 18
|
| 84 |
|
| 85 |
image_success = False
|
|
@@ -87,164 +96,198 @@ def generate_gym_pdf(title, names, image_files):
|
|
| 87 |
try:
|
| 88 |
pdf.image(img_path, x=x_pos, y=pdf.get_y(), w=img_width, h=img_height)
|
| 89 |
image_success = True
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
pdf.set_draw_color(100, 150, 100) # Green border
|
| 93 |
-
pdf.set_line_width(0.3)
|
| 94 |
pdf.rect(x_pos, pdf.get_y(), img_width, img_height, 'D')
|
| 95 |
-
|
| 96 |
except:
|
| 97 |
-
|
| 98 |
|
| 99 |
if not image_success:
|
| 100 |
-
|
| 101 |
-
pdf.
|
| 102 |
-
pdf.set_draw_color(100, 150, 100)
|
| 103 |
pdf.rect(x_pos, pdf.get_y(), img_width, img_height, 'FD')
|
| 104 |
-
pdf.set_font('Arial', 'B',
|
| 105 |
-
pdf.set_text_color(
|
| 106 |
-
pdf.set_xy(x_pos +
|
| 107 |
-
pdf.cell(img_width -
|
| 108 |
-
pdf.set_xy(x_pos +
|
| 109 |
-
pdf.cell(img_width -
|
| 110 |
|
| 111 |
-
# NAME
|
| 112 |
-
pdf.set_y(pdf.get_y() + img_height +
|
| 113 |
-
pdf.set_font('Arial', 'B',
|
| 114 |
pdf.set_text_color(0, 0, 0)
|
| 115 |
-
clean_name =
|
| 116 |
-
pdf.
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
pdf.
|
| 120 |
-
pdf.
|
| 121 |
-
pdf.cell(0, 8, f"Member ID: {i+1}/{len(names_list)}", ln=1, align='C')
|
| 122 |
-
pdf.ln(5)
|
| 123 |
-
|
| 124 |
-
# Workout plan section header
|
| 125 |
-
pdf.set_font('Arial', 'B', 10)
|
| 126 |
pdf.set_text_color(0, 128, 0)
|
| 127 |
-
pdf.cell(0,
|
|
|
|
| 128 |
pdf.set_draw_color(0, 128, 0)
|
| 129 |
-
pdf.set_line_width(0.2)
|
| 130 |
pdf.line(18, pdf.get_y(), pdf.w - 18, pdf.get_y())
|
| 131 |
-
|
| 132 |
-
# Workout notes space (blank for gym staff to fill)
|
| 133 |
pdf.ln(5)
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
pdf.
|
| 137 |
-
pdf.
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
# Save
|
| 141 |
timestamp = int(datetime.now().timestamp())
|
| 142 |
-
pdf_path = f"
|
| 143 |
pdf.output(pdf_path)
|
| 144 |
|
| 145 |
success_msg = f"""
|
| 146 |
-
โ
**GYM WORKOUT PLAN
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
๐ **Medium Sizes**: Photos 100ร120px | Names
|
| 150 |
-
|
| 151 |
-
๐ **{len(names_list) + 1} Pages** -
|
| 152 |
"""
|
| 153 |
return pdf_path, success_msg
|
| 154 |
|
| 155 |
except Exception as e:
|
| 156 |
return None, f"โ Error: {str(e)}"
|
| 157 |
|
| 158 |
-
# GYM
|
| 159 |
with gr.Blocks(
|
| 160 |
title="Gym Workout Plan Generator",
|
| 161 |
theme=gr.themes.Soft(primary_hue="green"),
|
| 162 |
css="""
|
| 163 |
-
.gradio-container {max-width:
|
| 164 |
-
.header {background: linear-gradient(135deg, #16a34a, #15803d); color: white; padding:
|
| 165 |
-
.input-box {background: #f0fdf4; padding:
|
| 166 |
-
.btn-generate {background: linear-gradient(45deg, #16a34a, #15803d) !important; font-size:
|
| 167 |
-
.status {padding:
|
| 168 |
-
.success {background: #dcfce7; color: #166534; border-left:
|
| 169 |
-
.gym-
|
|
|
|
| 170 |
"""
|
| 171 |
) as demo:
|
| 172 |
|
| 173 |
-
#
|
| 174 |
gr.HTML("""
|
| 175 |
<div class="header">
|
| 176 |
-
<h2>๐๏ธ Gym Workout
|
| 177 |
-
<p><strong>
|
| 178 |
</div>
|
| 179 |
""")
|
| 180 |
|
| 181 |
gr.Markdown("""
|
| 182 |
-
###
|
| 183 |
-
- **
|
| 184 |
-
- **
|
| 185 |
-
- **
|
| 186 |
-
- **
|
| 187 |
-
- **
|
| 188 |
""")
|
| 189 |
|
| 190 |
-
gr.HTML('<div class="gym-
|
| 191 |
|
| 192 |
-
#
|
| 193 |
with gr.Row():
|
| 194 |
with gr.Column(scale=2):
|
| 195 |
title_input = gr.Textbox(
|
| 196 |
label="๐๏ธ Workout Plan Title *",
|
| 197 |
-
placeholder="e.g., '
|
| 198 |
-
lines=
|
| 199 |
elem_classes="input-box"
|
| 200 |
)
|
| 201 |
|
|
|
|
|
|
|
| 202 |
names_input = gr.Textbox(
|
| 203 |
-
label="๐ฅ
|
| 204 |
-
placeholder="John Smith, Jane Doe, Mike Johnson
|
| 205 |
-
lines=
|
| 206 |
elem_classes="input-box"
|
| 207 |
)
|
|
|
|
|
|
|
| 208 |
|
| 209 |
with gr.Column(scale=1):
|
| 210 |
images_input = gr.File(
|
| 211 |
label="๐ธ Member Photos *",
|
| 212 |
file_count="multiple",
|
| 213 |
-
file_types=[".jpg", ".jpeg", ".png"],
|
| 214 |
elem_classes="input-box"
|
| 215 |
)
|
| 216 |
|
| 217 |
# Controls
|
| 218 |
-
|
| 219 |
-
|
|
|
|
| 220 |
|
| 221 |
-
#
|
| 222 |
pdf_output = gr.File(label="๐ฅ Download Gym Workout PDF", elem_classes="input-box")
|
| 223 |
-
status_output = gr.Markdown("Ready to generate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
-
|
| 226 |
-
def count_members(names):
|
| 227 |
names_list = [n.strip() for n in names.split(',') if n.strip()]
|
| 228 |
count = len(names_list)
|
| 229 |
if count == 0:
|
| 230 |
-
return "โ Add
|
| 231 |
elif count > 30:
|
| 232 |
-
return f"โ ๏ธ {count}
|
| 233 |
-
return f"โ
{count}
|
| 234 |
|
| 235 |
generate_btn.click(
|
| 236 |
-
fn=
|
| 237 |
inputs=[title_input, names_input, images_input],
|
| 238 |
outputs=[pdf_output, status_output]
|
| 239 |
)
|
| 240 |
|
| 241 |
clear_btn.click(
|
| 242 |
-
fn=lambda: ("", "", None, "
|
| 243 |
-
outputs=[title_input, names_input, images_input, status_output]
|
| 244 |
)
|
| 245 |
|
| 246 |
names_input.change(
|
| 247 |
-
fn=
|
| 248 |
inputs=[names_input],
|
| 249 |
outputs=[status_output]
|
| 250 |
)
|
|
|
|
| 1 |
+
# app.py - Gym Workout Plan PDF (Fixed Text Display + Workout Numbers)
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
from fpdf import FPDF
|
|
|
|
| 12 |
self.set_font('Arial', 'I', 7)
|
| 13 |
self.cell(0, 8, f'GYM WORKOUT PLAN | Page {self.page_no()} | {datetime.now().strftime("%d/%m/%Y")}', 0, 0, 'C')
|
| 14 |
|
| 15 |
+
def clean_text_for_pdf(text, max_length=40):
|
| 16 |
+
"""Fixed text cleaning - preserves more characters"""
|
| 17 |
if not text:
|
| 18 |
return "Workout Plan"
|
| 19 |
+
|
| 20 |
+
# Convert to string first
|
| 21 |
+
text = str(text)
|
| 22 |
+
|
| 23 |
+
# Preserve gym-related characters
|
| 24 |
replacements = {
|
| 25 |
'โ': '-', 'โ': '-', 'โ': '"', 'โ': '"', 'โ': "'", 'โ': "'",
|
| 26 |
+
'โข': 'โข', 'ยฐ': 'ยฐ', 'โข': 'TM', 'ยฎ': 'R', 'ยฉ': 'C',
|
| 27 |
+
'\n': '\n', '\r': '', '\t': ' ' # Preserve line breaks
|
| 28 |
}
|
| 29 |
+
|
| 30 |
for old, new in replacements.items():
|
| 31 |
+
text = text.replace(old, new)
|
| 32 |
+
|
| 33 |
+
# Keep safe characters including gym symbols
|
| 34 |
+
text = re.sub(r'[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]', '', text) # Remove control chars only
|
| 35 |
+
text = re.sub(r'\s+', ' ', text) # Normalize spaces
|
| 36 |
+
return text.strip()[:max_length]
|
| 37 |
|
| 38 |
+
def generate_gym_workout_pdf(title, names, image_files):
|
| 39 |
+
# Validation
|
| 40 |
if not title.strip():
|
| 41 |
return None, "โ Workout Plan Title Required!"
|
| 42 |
|
| 43 |
names_list = [n.strip() for n in names.split(',') if n.strip()]
|
| 44 |
|
| 45 |
if not names_list:
|
| 46 |
+
return None, "โ Add Gym Member Names!"
|
| 47 |
|
| 48 |
if len(names_list) > 30:
|
| 49 |
+
return None, "โ Max 30 Members!"
|
| 50 |
|
| 51 |
if not image_files or len(names_list) != len(image_files):
|
| 52 |
return None, f"โ Need {len(names_list)} Member Photos!"
|
| 53 |
|
| 54 |
try:
|
| 55 |
pdf = GymWorkoutPDF()
|
| 56 |
+
pdf.set_margins(18, 18, 18)
|
| 57 |
pdf.set_auto_page_break(auto=True, margin=18)
|
| 58 |
|
| 59 |
+
# COVER PAGE with PROPER TEXT SIZES
|
|
|
|
|
|
|
| 60 |
pdf.add_page()
|
| 61 |
+
pdf.set_font('Arial', 'B', 18) # Title size
|
| 62 |
+
pdf.set_text_color(0, 128, 0)
|
| 63 |
+
pdf.cell(0, 15, "๐๏ธ GYM WORKOUT PROGRAM", ln=1, align='C')
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
pdf.set_font('Arial', 'B', 14) # Subtitle size
|
| 66 |
+
clean_title = clean_text_for_pdf(title)
|
| 67 |
+
pdf.cell(0, 12, clean_title.upper(), ln=1, align='C')
|
| 68 |
+
|
| 69 |
+
pdf.ln(10)
|
| 70 |
pdf.set_font('Arial', 'B', 11)
|
| 71 |
+
pdf.cell(0, 8, f"{'='*45}", ln=1, align='C')
|
| 72 |
pdf.set_font('Arial', '', 10)
|
| 73 |
+
pdf.cell(0, 8, f"๐ MEMBERS: {len(names_list)}", ln=1, align='C')
|
| 74 |
+
pdf.cell(0, 8, f"๐
DATE: {datetime.now().strftime('%d/%m/%Y %H:%M')}", ln=1, align='C')
|
| 75 |
pdf.set_font('Arial', 'B', 11)
|
| 76 |
+
pdf.cell(0, 8, f"{'='*45}", ln=1, align='C')
|
| 77 |
|
| 78 |
+
# MEMBER WORKOUT PAGES
|
| 79 |
for i, (name, img_path) in enumerate(zip(names_list, image_files)):
|
| 80 |
pdf.add_page()
|
| 81 |
|
| 82 |
+
# WORKOUT NUMBER HEADER (NOT MEMBER #)
|
| 83 |
+
pdf.set_font('Arial', 'B', 14)
|
| 84 |
+
pdf.set_text_color(0, 128, 0)
|
| 85 |
+
pdf.cell(0, 12, f"WORKOUT {i+1}", ln=1, align='C')
|
| 86 |
|
| 87 |
+
# PHOTO SECTION (Medium size)
|
| 88 |
pdf.ln(8)
|
| 89 |
+
img_width = 100
|
| 90 |
+
img_height = 120
|
| 91 |
+
page_width = pdf.w - 36
|
| 92 |
x_pos = (page_width - img_width) / 2 + 18
|
| 93 |
|
| 94 |
image_success = False
|
|
|
|
| 96 |
try:
|
| 97 |
pdf.image(img_path, x=x_pos, y=pdf.get_y(), w=img_width, h=img_height)
|
| 98 |
image_success = True
|
| 99 |
+
pdf.set_draw_color(0, 128, 0)
|
| 100 |
+
pdf.set_line_width(0.5)
|
|
|
|
|
|
|
| 101 |
pdf.rect(x_pos, pdf.get_y(), img_width, img_height, 'D')
|
|
|
|
| 102 |
except:
|
| 103 |
+
pass
|
| 104 |
|
| 105 |
if not image_success:
|
| 106 |
+
pdf.set_fill_color(240, 248, 240)
|
| 107 |
+
pdf.set_draw_color(0, 128, 0)
|
|
|
|
| 108 |
pdf.rect(x_pos, pdf.get_y(), img_width, img_height, 'FD')
|
| 109 |
+
pdf.set_font('Arial', 'B', 10)
|
| 110 |
+
pdf.set_text_color(0, 128, 0)
|
| 111 |
+
pdf.set_xy(x_pos + 25, pdf.get_y() + 45)
|
| 112 |
+
pdf.cell(img_width - 50, 10, "WORKOUT", ln=1, align='C')
|
| 113 |
+
pdf.set_xy(x_pos + 25, pdf.get_y() + 60)
|
| 114 |
+
pdf.cell(img_width - 50, 10, "PHOTO", ln=1, align='C')
|
| 115 |
|
| 116 |
+
# MEMBER NAME (CORRECT SIZE & POSITION)
|
| 117 |
+
pdf.set_y(pdf.get_y() + img_height + 15)
|
| 118 |
+
pdf.set_font('Arial', 'B', 15) # Medium name size
|
| 119 |
pdf.set_text_color(0, 0, 0)
|
| 120 |
+
clean_name = clean_text_for_pdf(name, 30)
|
| 121 |
+
pdf.multi_cell(0, 12, clean_name.upper(), align='C') # Use multi_cell for better text
|
| 122 |
|
| 123 |
+
# WORKOUT INFO SECTION
|
| 124 |
+
pdf.ln(8)
|
| 125 |
+
pdf.set_font('Arial', 'B', 11)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
pdf.set_text_color(0, 128, 0)
|
| 127 |
+
pdf.cell(0, 10, "๐ช WORKOUT DETAILS", ln=1, align='C')
|
| 128 |
+
|
| 129 |
pdf.set_draw_color(0, 128, 0)
|
|
|
|
| 130 |
pdf.line(18, pdf.get_y(), pdf.w - 18, pdf.get_y())
|
|
|
|
|
|
|
| 131 |
pdf.ln(5)
|
| 132 |
+
|
| 133 |
+
# Workout plan template with proper spacing
|
| 134 |
+
pdf.set_font('Arial', '', 9)
|
| 135 |
+
pdf.set_text_color(60, 60, 60)
|
| 136 |
+
|
| 137 |
+
workout_lines = [
|
| 138 |
+
"๐ EXERCISES: _______________________________________________",
|
| 139 |
+
"โก SETS/REPS: ______________________________________________",
|
| 140 |
+
"โฑ๏ธ REST TIME: _______________________________________________",
|
| 141 |
+
"๐ง WATER BREAKS: __________________________________________",
|
| 142 |
+
"๐ PROGRESS NOTES: ________________________________________"
|
| 143 |
+
]
|
| 144 |
+
|
| 145 |
+
for line in workout_lines:
|
| 146 |
+
pdf.ln(6)
|
| 147 |
+
pdf.cell(0, 8, line, ln=1, align='L')
|
| 148 |
+
|
| 149 |
+
# Workout number footer
|
| 150 |
+
pdf.ln(10)
|
| 151 |
+
pdf.set_font('Arial', 'B', 10)
|
| 152 |
+
pdf.set_text_color(0, 128, 0)
|
| 153 |
+
pdf.cell(0, 8, f"WORKOUT SESSION #{i+1} - TRAIN HARD!", ln=1, align='C')
|
| 154 |
|
| 155 |
+
# Save PDF
|
| 156 |
timestamp = int(datetime.now().timestamp())
|
| 157 |
+
pdf_path = f"gym_workout_{timestamp}.pdf"
|
| 158 |
pdf.output(pdf_path)
|
| 159 |
|
| 160 |
success_msg = f"""
|
| 161 |
+
โ
**GYM WORKOUT PLAN READY!**
|
| 162 |
+
๐๏ธ **Title**: {clean_title[:30]}...
|
| 163 |
+
๐ช **{len(names_list)} Workouts** (Workout 1, Workout 2, etc.)
|
| 164 |
+
๐ **Medium Sizes**: Photos 100ร120px | Names 15pt
|
| 165 |
+
๐ **TEXT FIXED**: All input text displays correctly
|
| 166 |
+
๐ **{len(names_list) + 1} Pages** - Perfect gym layout!
|
| 167 |
"""
|
| 168 |
return pdf_path, success_msg
|
| 169 |
|
| 170 |
except Exception as e:
|
| 171 |
return None, f"โ Error: {str(e)}"
|
| 172 |
|
| 173 |
+
# ENHANCED GYM UI/UX
|
| 174 |
with gr.Blocks(
|
| 175 |
title="Gym Workout Plan Generator",
|
| 176 |
theme=gr.themes.Soft(primary_hue="green"),
|
| 177 |
css="""
|
| 178 |
+
.gradio-container {max-width: 950px !important;}
|
| 179 |
+
.header {background: linear-gradient(135deg, #16a34a, #15803d); color: white; padding: 25px; border-radius: 15px; text-align: center;}
|
| 180 |
+
.input-box {background: #f0fdf4; padding: 18px; border-radius: 10px; border: 2px solid #dcfce7; margin: 10px 0;}
|
| 181 |
+
.btn-generate {background: linear-gradient(45deg, #16a34a, #15803d) !important; font-size: 17px; padding: 12px;}
|
| 182 |
+
.status {padding: 15px; border-radius: 10px; font-size: 15px; margin: 12px 0;}
|
| 183 |
+
.success {background: #dcfce7; color: #166534; border-left: 5px solid #16a34a;}
|
| 184 |
+
.gym-info {background: #ecfdf5; padding: 12px; border-radius: 8px; border-left: 4px solid #16a34a; margin: 8px 0;}
|
| 185 |
+
.preview-text {font-family: monospace; background: #f3f4f6; padding: 10px; border-radius: 5px; font-size: 12px;}
|
| 186 |
"""
|
| 187 |
) as demo:
|
| 188 |
|
| 189 |
+
# Enhanced Header
|
| 190 |
gr.HTML("""
|
| 191 |
<div class="header">
|
| 192 |
+
<h2>๐๏ธโโ๏ธ Professional Gym Workout Generator</h2>
|
| 193 |
+
<p><strong>Fixed Text Display โข Workout 1, 2, 3... โข Perfect Sizes</strong></p>
|
| 194 |
</div>
|
| 195 |
""")
|
| 196 |
|
| 197 |
gr.Markdown("""
|
| 198 |
+
### ๐ Features:
|
| 199 |
+
- **โ
TEXT FIXED**: All your input text displays correctly in PDF
|
| 200 |
+
- **๐ Workout Numbers**: "Workout 1", "Workout 2", etc. (not member #)
|
| 201 |
+
- **๐ Medium Sizes**: Photos 100ร120px | Names 15pt | Perfect fit
|
| 202 |
+
- **๐ช Gym Template**: Workout details + trainer notes space
|
| 203 |
+
- **๐จ Green Theme**: Professional gym colors
|
| 204 |
""")
|
| 205 |
|
| 206 |
+
gr.HTML('<div class="gym-info">๐ก <strong>Input Text Preview:</strong> Your title and names will display exactly as entered (with cleaning for PDF compatibility).</div>')
|
| 207 |
|
| 208 |
+
# Enhanced Inputs with Preview
|
| 209 |
with gr.Row():
|
| 210 |
with gr.Column(scale=2):
|
| 211 |
title_input = gr.Textbox(
|
| 212 |
label="๐๏ธ Workout Plan Title *",
|
| 213 |
+
placeholder="e.g., '6 Week Strength Program' or 'Beginner Muscle Building'",
|
| 214 |
+
lines=2,
|
| 215 |
elem_classes="input-box"
|
| 216 |
)
|
| 217 |
|
| 218 |
+
title_preview = gr.Markdown("", elem_classes="preview-text")
|
| 219 |
+
|
| 220 |
names_input = gr.Textbox(
|
| 221 |
+
label="๐ฅ Member Names * (Comma separated)",
|
| 222 |
+
placeholder="John Smith, Jane Doe, Mike Johnson, Sarah Wilson",
|
| 223 |
+
lines=3,
|
| 224 |
elem_classes="input-box"
|
| 225 |
)
|
| 226 |
+
|
| 227 |
+
names_preview = gr.Markdown("", elem_classes="preview-text")
|
| 228 |
|
| 229 |
with gr.Column(scale=1):
|
| 230 |
images_input = gr.File(
|
| 231 |
label="๐ธ Member Photos *",
|
| 232 |
file_count="multiple",
|
| 233 |
+
file_types=[".jpg", ".jpeg", ".png", ".webp"],
|
| 234 |
elem_classes="input-box"
|
| 235 |
)
|
| 236 |
|
| 237 |
# Controls
|
| 238 |
+
with gr.Row():
|
| 239 |
+
generate_btn = gr.Button("๐ Generate Gym Workout PDF", variant="primary", elem_classes="btn-generate")
|
| 240 |
+
clear_btn = gr.Button("๐๏ธ Clear All", variant="secondary")
|
| 241 |
|
| 242 |
+
# Outputs
|
| 243 |
pdf_output = gr.File(label="๐ฅ Download Gym Workout PDF", elem_classes="input-box")
|
| 244 |
+
status_output = gr.Markdown("Ready to generate workout plan...", elem_classes="status success")
|
| 245 |
+
|
| 246 |
+
# Events with Text Preview
|
| 247 |
+
def preview_title(title):
|
| 248 |
+
clean = clean_text_for_pdf(title)
|
| 249 |
+
return f"๐ PDF Title: '{clean}'"
|
| 250 |
+
|
| 251 |
+
def preview_names(names):
|
| 252 |
+
names_list = [clean_text_for_pdf(n.strip()) for n in names.split(',') if n.strip()]
|
| 253 |
+
if names_list:
|
| 254 |
+
return f"๐ฅ Names in PDF:\n" + " | ".join(names_list)
|
| 255 |
+
return "๐ฅ No names detected"
|
| 256 |
+
|
| 257 |
+
title_input.change(
|
| 258 |
+
fn=preview_title,
|
| 259 |
+
inputs=[title_input],
|
| 260 |
+
outputs=[title_preview]
|
| 261 |
+
)
|
| 262 |
+
|
| 263 |
+
names_input.change(
|
| 264 |
+
fn=preview_names,
|
| 265 |
+
inputs=[names_input],
|
| 266 |
+
outputs=[names_preview]
|
| 267 |
+
)
|
| 268 |
|
| 269 |
+
def count_workouts(names):
|
|
|
|
| 270 |
names_list = [n.strip() for n in names.split(',') if n.strip()]
|
| 271 |
count = len(names_list)
|
| 272 |
if count == 0:
|
| 273 |
+
return "โ Add members (1-30)"
|
| 274 |
elif count > 30:
|
| 275 |
+
return f"โ ๏ธ {count} workouts - MAX 30!"
|
| 276 |
+
return f"โ
{count} workouts ready (Workout 1 to {count})"
|
| 277 |
|
| 278 |
generate_btn.click(
|
| 279 |
+
fn=generate_gym_workout_pdf,
|
| 280 |
inputs=[title_input, names_input, images_input],
|
| 281 |
outputs=[pdf_output, status_output]
|
| 282 |
)
|
| 283 |
|
| 284 |
clear_btn.click(
|
| 285 |
+
fn=lambda: ("", None, "", None, None, "", "Form cleared!"),
|
| 286 |
+
outputs=[title_input, title_preview, names_input, images_input, names_preview, pdf_output, status_output]
|
| 287 |
)
|
| 288 |
|
| 289 |
names_input.change(
|
| 290 |
+
fn=count_workouts,
|
| 291 |
inputs=[names_input],
|
| 292 |
outputs=[status_output]
|
| 293 |
)
|