Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# app.py -
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
from fpdf import FPDF
|
|
@@ -6,237 +6,273 @@ import os
|
|
| 6 |
import tempfile
|
| 7 |
import re
|
| 8 |
from datetime import datetime
|
| 9 |
-
from
|
| 10 |
-
|
| 11 |
|
| 12 |
-
class
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def footer(self):
|
| 14 |
self.set_y(-15)
|
| 15 |
self.set_font('Arial', 'I', 8)
|
| 16 |
-
self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')
|
| 17 |
|
| 18 |
-
def
|
| 19 |
-
"""Clean text
|
| 20 |
if not text:
|
| 21 |
-
return ""
|
|
|
|
|
|
|
| 22 |
replacements = {
|
| 23 |
'โ': '-', 'โ': '-', 'โ': '"', 'โ': '"', 'โ': "'", 'โ': "'",
|
| 24 |
-
'โข': '
|
| 25 |
-
'โฌ': 'EUR', 'ยฃ': 'GBP', 'ยฅ': 'JPY'
|
| 26 |
}
|
|
|
|
| 27 |
for old, new in replacements.items():
|
| 28 |
-
text = text.replace(old, new)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
def
|
| 34 |
-
#
|
| 35 |
if not title or not title.strip():
|
| 36 |
-
return None,
|
| 37 |
|
| 38 |
names_list = [n.strip() for n in names.split(',') if n.strip()]
|
| 39 |
|
| 40 |
if not names_list:
|
| 41 |
-
return None,
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
if not image_files:
|
| 44 |
-
return None,
|
| 45 |
|
| 46 |
if len(names_list) != len(image_files):
|
| 47 |
-
return None,
|
| 48 |
-
|
| 49 |
-
# Limit to 30 items max
|
| 50 |
-
if len(names_list) > 30:
|
| 51 |
-
return None, None, "โ Max 30 items allowed!"
|
| 52 |
|
| 53 |
try:
|
| 54 |
-
|
| 55 |
-
pdf
|
| 56 |
-
pdf.
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
|
|
|
|
| 61 |
pdf.add_page()
|
| 62 |
-
pdf.set_font('Arial', 'B',
|
| 63 |
-
pdf.
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
-
pdf.ln(
|
| 71 |
-
pdf.set_font('Arial', '
|
| 72 |
-
pdf.cell(0,
|
| 73 |
-
pdf.cell(0,
|
| 74 |
|
|
|
|
| 75 |
for i, (name, img_path) in enumerate(zip(names_list, image_files)):
|
| 76 |
pdf.add_page()
|
| 77 |
-
clean_name = clean_text(name, 40)
|
| 78 |
-
pdf.set_font('Arial', 'B', 16)
|
| 79 |
-
pdf.cell(0, 12, clean_name.upper(), ln=1, align='C')
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
x_pos = (pdf.w - img_width) / 2
|
| 89 |
-
pdf.image(img_path, x=x_pos, y=40, w=img_width)
|
| 90 |
-
image_added = True
|
| 91 |
-
except:
|
| 92 |
-
pass
|
| 93 |
-
|
| 94 |
-
if not image_added:
|
| 95 |
-
pdf.set_font('Arial', '', 12)
|
| 96 |
-
pdf.cell(0, 10, "[IMAGE PLACEHOLDER]", ln=1, align='C')
|
| 97 |
-
|
| 98 |
-
pdf_path = f"pdf_{int(datetime.now().timestamp())}.pdf"
|
| 99 |
-
pdf.output(pdf_path)
|
| 100 |
-
|
| 101 |
-
# Video Generation - Full HD 1920x1080
|
| 102 |
-
clips = []
|
| 103 |
-
hd_width, hd_height = 1920, 1080
|
| 104 |
-
text_height = 150 # Space for name below image
|
| 105 |
-
|
| 106 |
-
for i, (name, img_path) in enumerate(zip(names_list, image_files)):
|
| 107 |
-
clean_name = clean_text(name, 40)
|
| 108 |
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
| 117 |
-
text_clip = TextClip(
|
| 118 |
-
f"{clean_name.upper()}\nID: {i+1}",
|
| 119 |
-
fontsize=80, color='white', font='Arial-Bold',
|
| 120 |
-
size=(hd_width, text_height), bg_color='black', method='caption'
|
| 121 |
-
).set_position(("center", hd_height - text_height - 25))
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
#
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
fontsize=100, color='white', bg_color='blue',
|
| 150 |
-
size=(hd_width, hd_height)
|
| 151 |
-
).set_duration(3) # 3 sec intro
|
| 152 |
-
video = concatenate_videoclips([title_clip, video])
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
|
| 158 |
-
return pdf_path, video_path, success_msg
|
| 159 |
|
| 160 |
except Exception as e:
|
| 161 |
-
return None,
|
| 162 |
|
| 163 |
-
#
|
| 164 |
with gr.Blocks(
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
css="""
|
| 167 |
-
.gradio-container {max-width:
|
| 168 |
-
.
|
| 169 |
-
.
|
| 170 |
-
.status {
|
|
|
|
|
|
|
|
|
|
| 171 |
"""
|
| 172 |
) as demo:
|
| 173 |
-
gr.Markdown(
|
| 174 |
-
"""
|
| 175 |
-
# ๐ HD PDF & Video Generator
|
| 176 |
-
**Create Professional PDF & Full HD Video Slideshow**
|
| 177 |
-
|
| 178 |
-
### Instructions:
|
| 179 |
-
- **Title**: Document/Video title (required)
|
| 180 |
-
- **Plan**: Optional description
|
| 181 |
-
- **Names**: Comma-separated (e.g., "John Doe, Jane Smith") - Max 30
|
| 182 |
-
- **Images**: Upload matching images (uploaded below names input for UX)
|
| 183 |
-
- **Slide Duration**: Seconds per slide in video
|
| 184 |
-
- Video: Full HD 1920x1080, name below image, IDs 1 to N
|
| 185 |
-
- Click Generate for PDF & Video downloads
|
| 186 |
-
"""
|
| 187 |
-
)
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
with gr.Column(scale=2):
|
| 191 |
title_input = gr.Textbox(
|
| 192 |
-
label="๐ Title
|
| 193 |
-
placeholder="Enter title
|
| 194 |
-
lines=
|
| 195 |
-
elem_classes="input-
|
| 196 |
-
)
|
| 197 |
-
plan_input = gr.Textbox(
|
| 198 |
-
label="๐ Plan/Description (Optional)",
|
| 199 |
-
placeholder="Enter details here...",
|
| 200 |
-
lines=4
|
| 201 |
)
|
|
|
|
| 202 |
names_input = gr.Textbox(
|
| 203 |
-
label="๐ฅ Names (Comma
|
| 204 |
-
placeholder="
|
| 205 |
-
lines=
|
|
|
|
| 206 |
)
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
| 211 |
)
|
| 212 |
|
| 213 |
with gr.Column(scale=1):
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
label="โฑ๏ธ Duration per Slide (Seconds)"
|
| 220 |
)
|
| 221 |
-
generate_btn = gr.Button("๐ Generate PDF & Video", variant="primary", size="lg")
|
| 222 |
-
clear_btn = gr.Button("๐๏ธ Clear All", variant="secondary")
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
| 227 |
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
-
# Event handlers
|
| 231 |
generate_btn.click(
|
| 232 |
-
fn=
|
| 233 |
-
inputs=[title_input, plan_input, names_input, images_input
|
| 234 |
-
outputs=[pdf_output,
|
| 235 |
)
|
| 236 |
|
| 237 |
clear_btn.click(
|
| 238 |
-
fn=
|
| 239 |
-
outputs=[title_input, plan_input, names_input, images_input,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
)
|
| 241 |
|
| 242 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
# app.py - PDF Generator ONLY (No MoviePy - HF Spaces Compatible)
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
from fpdf import FPDF
|
|
|
|
| 6 |
import tempfile
|
| 7 |
import re
|
| 8 |
from datetime import datetime
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import io
|
| 11 |
|
| 12 |
+
class ProfessionalPDF(FPDF):
|
| 13 |
+
def header(self):
|
| 14 |
+
self.set_font('Arial', 'B', 12)
|
| 15 |
+
self.cell(0, 10, 'Professional Document', 0, 1, 'C')
|
| 16 |
+
|
| 17 |
def footer(self):
|
| 18 |
self.set_y(-15)
|
| 19 |
self.set_font('Arial', 'I', 8)
|
| 20 |
+
self.cell(0, 10, f'Page {self.page_no()} | Generated {datetime.now().strftime("%Y-%m-%d")}', 0, 0, 'C')
|
| 21 |
|
| 22 |
+
def clean_text_for_pdf(text, max_length=100):
|
| 23 |
+
"""Clean text to avoid PDF encoding issues"""
|
| 24 |
if not text:
|
| 25 |
+
return "Untitled"
|
| 26 |
+
|
| 27 |
+
# Replace problematic characters
|
| 28 |
replacements = {
|
| 29 |
'โ': '-', 'โ': '-', 'โ': '"', 'โ': '"', 'โ': "'", 'โ': "'",
|
| 30 |
+
'โข': '*', 'ยฐ': 'deg', 'โข': 'TM', 'ยฎ': 'R', 'ยฉ': 'C',
|
| 31 |
+
'โฌ': 'EUR', 'ยฃ': 'GBP', 'ยฅ': 'JPY', '\n': ' '
|
| 32 |
}
|
| 33 |
+
|
| 34 |
for old, new in replacements.items():
|
| 35 |
+
text = str(text).replace(old, new)
|
| 36 |
+
|
| 37 |
+
# Remove remaining special chars
|
| 38 |
+
text = re.sub(r'[^\w\s\-.,!?\(\)\[\]:;0-9]', '', text)
|
| 39 |
+
text = re.sub(r'\s+', ' ', text) # Normalize whitespace
|
| 40 |
+
return text.strip()[:max_length]
|
| 41 |
|
| 42 |
+
def generate_pdf(title, plan, names, image_files):
|
| 43 |
+
# Fast validation
|
| 44 |
if not title or not title.strip():
|
| 45 |
+
return None, "โ Title is required!"
|
| 46 |
|
| 47 |
names_list = [n.strip() for n in names.split(',') if n.strip()]
|
| 48 |
|
| 49 |
if not names_list:
|
| 50 |
+
return None, "โ Enter at least one name!"
|
| 51 |
+
|
| 52 |
+
if len(names_list) > 30:
|
| 53 |
+
return None, "โ Maximum 30 names allowed!"
|
| 54 |
|
| 55 |
if not image_files:
|
| 56 |
+
return None, "โ Upload images (matching names count)!"
|
| 57 |
|
| 58 |
if len(names_list) != len(image_files):
|
| 59 |
+
return None, f"โ Mismatch: {len(names_list)} names, {len(image_files)} images"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
try:
|
| 62 |
+
pdf = ProfessionalPDF()
|
| 63 |
+
pdf.set_margins(20, 20, 20)
|
| 64 |
+
pdf.set_auto_page_break(auto=True, margin=20)
|
| 65 |
|
| 66 |
+
# Clean inputs
|
| 67 |
+
clean_title = clean_text_for_pdf(title, 80)
|
| 68 |
+
clean_plan = clean_text_for_pdf(plan, 800)
|
| 69 |
|
| 70 |
+
# COVER PAGE
|
| 71 |
pdf.add_page()
|
| 72 |
+
pdf.set_font('Arial', 'B', 28)
|
| 73 |
+
pdf.set_text_color(0, 51, 102) # Dark blue
|
| 74 |
+
pdf.cell(0, 20, clean_title, ln=1, align='C')
|
| 75 |
|
| 76 |
+
pdf.ln(15)
|
| 77 |
+
pdf.set_font('Arial', '', 14)
|
| 78 |
+
pdf.set_text_color(0, 0, 0)
|
| 79 |
+
pdf.multi_cell(0, 10, clean_plan)
|
| 80 |
|
| 81 |
+
pdf.ln(20)
|
| 82 |
+
pdf.set_font('Arial', 'B', 12)
|
| 83 |
+
pdf.cell(0, 10, f"TOTAL PARTICIPANTS: {len(names_list)}", ln=1, align='C')
|
| 84 |
+
pdf.cell(0, 10, f"GENERATED: {datetime.now().strftime('%Y-%m-%d %H:%M')}", ln=1, align='C')
|
| 85 |
|
| 86 |
+
# INDIVIDUAL PAGES (Image UP, Name DOWN)
|
| 87 |
for i, (name, img_path) in enumerate(zip(names_list, image_files)):
|
| 88 |
pdf.add_page()
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
# Clean name
|
| 91 |
+
clean_name = clean_text_for_pdf(name, 50)
|
| 92 |
|
| 93 |
+
# HEADER WITH ID
|
| 94 |
+
pdf.set_font('Arial', 'B', 18)
|
| 95 |
+
pdf.set_text_color(51, 51, 153) # Blue
|
| 96 |
+
pdf.cell(0, 15, f"PARTICIPANT #{i+1}", ln=1, align='C')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
# IMAGE SECTION (UPPER PART)
|
| 99 |
+
pdf.ln(10)
|
| 100 |
+
try:
|
| 101 |
+
if os.path.exists(img_path):
|
| 102 |
+
# Calculate centered position
|
| 103 |
+
img_width = 140
|
| 104 |
+
page_width = pdf.w - 40 # Account for margins
|
| 105 |
+
x_pos = (page_width - img_width) / 2 + 20
|
| 106 |
|
| 107 |
+
pdf.image(img_path, x=x_pos, y=pdf.get_y(), w=img_width, h=180)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
# Image border
|
| 110 |
+
pdf.set_draw_color(200, 200, 200)
|
| 111 |
+
pdf.line(x_pos, pdf.get_y(), x_pos + img_width, pdf.get_y())
|
| 112 |
+
pdf.line(x_pos + img_width, pdf.get_y(), x_pos + img_width, pdf.get_y() + 180)
|
| 113 |
+
pdf.line(x_pos + img_width, pdf.get_y() + 180, x_pos, pdf.get_y() + 180)
|
| 114 |
+
pdf.line(x_pos, pdf.get_y() + 180, x_pos, pdf.get_y())
|
| 115 |
+
|
| 116 |
+
else:
|
| 117 |
+
# Placeholder rectangle
|
| 118 |
+
img_width = 140
|
| 119 |
+
x_pos = (pdf.w - img_width) / 2
|
| 120 |
+
pdf.set_fill_color(240, 240, 240)
|
| 121 |
+
pdf.rect(x_pos, pdf.get_y(), img_width, 180, 'F')
|
| 122 |
+
pdf.set_font('Arial', '', 12)
|
| 123 |
+
pdf.set_xy(x_pos + 10, pdf.get_y() + 80)
|
| 124 |
+
pdf.multi_cell(img_width - 20, 10, "IMAGE\nNOT\nFOUND", align='C')
|
| 125 |
+
|
| 126 |
+
except Exception:
|
| 127 |
+
# Fallback placeholder
|
| 128 |
+
img_width = 140
|
| 129 |
+
x_pos = (pdf.w - img_width) / 2
|
| 130 |
+
pdf.set_fill_color(240, 240, 240)
|
| 131 |
+
pdf.rect(x_pos, pdf.get_y(), img_width, 180, 'F')
|
| 132 |
+
pdf.set_font('Arial', '', 12)
|
| 133 |
+
pdf.set_xy(x_pos + 10, pdf.get_y() + 80)
|
| 134 |
+
pdf.multi_cell(img_width - 20, 10, "IMAGE\nERROR", align='C')
|
| 135 |
+
|
| 136 |
+
# NAME SECTION (LOWER PART - BELOW IMAGE)
|
| 137 |
+
pdf.ln(200) # Move below image area
|
| 138 |
+
pdf.set_font('Arial', 'B', 22)
|
| 139 |
+
pdf.set_text_color(0, 0, 0)
|
| 140 |
+
pdf.cell(0, 20, clean_name.upper(), ln=1, align='C')
|
| 141 |
+
|
| 142 |
+
pdf.set_font('Arial', '', 12)
|
| 143 |
+
pdf.set_text_color(100, 100, 100)
|
| 144 |
+
pdf.cell(0, 10, f"Participant ID: {i+1} of {len(names_list)}", ln=1, align='C')
|
| 145 |
+
pdf.cell(0, 10, f"Generated: {datetime.now().strftime('%d/%m/%Y')}", ln=1, align='C')
|
| 146 |
|
| 147 |
+
# Output to file directly
|
| 148 |
+
timestamp = int(datetime.now().timestamp())
|
| 149 |
+
pdf_path = f"professional_pdf_{timestamp}.pdf"
|
| 150 |
+
pdf.output(pdf_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
+
success_msg = f"""
|
| 153 |
+
โ
**PDF Generated Successfully!**
|
| 154 |
+
๐ **Title**: {clean_title[:50]}...
|
| 155 |
+
๐ฅ **{len(names_list)} Participants** (IDs 1-{len(names_list)})
|
| 156 |
+
๐ **{len(names_list) + 1} Pages** (Cover + Participants)
|
| 157 |
+
๐ผ๏ธ **Images**: UP | **Names**: DOWN layout
|
| 158 |
+
๐พ Ready for download!
|
| 159 |
+
"""
|
| 160 |
|
| 161 |
+
return pdf_path, success_msg
|
|
|
|
| 162 |
|
| 163 |
except Exception as e:
|
| 164 |
+
return None, f"โ Error: {str(e)}\nPlease check your inputs and try again."
|
| 165 |
|
| 166 |
+
# Professional UI/UX with Full HD View Support
|
| 167 |
with gr.Blocks(
|
| 168 |
+
title="Professional PDF Generator",
|
| 169 |
+
theme=gr.themes.Soft(
|
| 170 |
+
primary_hue="blue",
|
| 171 |
+
secondary_hue="gray",
|
| 172 |
+
neutral_hue="stone"
|
| 173 |
+
),
|
| 174 |
css="""
|
| 175 |
+
.gradio-container {max-width: 1400px !important; margin: auto;}
|
| 176 |
+
.header {background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 30px; border-radius: 15px; text-align: center;}
|
| 177 |
+
.input-section {background: #f8fafc; padding: 20px; border-radius: 10px; margin: 10px 0; border-left: 4px solid #3b82f6;}
|
| 178 |
+
.status-success {background: #dcfce7; color: #166534; padding: 15px; border-radius: 8px; border-left: 4px solid #22c55e;}
|
| 179 |
+
.status-error {background: #fef2f2; color: #dc2626; padding: 15px; border-radius: 8px; border-left: 4px solid #ef4444;}
|
| 180 |
+
.btn-primary {background: linear-gradient(45deg, #3b82f6, #1d4ed8) !important;}
|
| 181 |
+
.output-zone {background: #f1f5f9; padding: 20px; border-radius: 10px; margin-top: 20px;}
|
| 182 |
"""
|
| 183 |
) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
+
# Header
|
| 186 |
+
with gr.Row():
|
| 187 |
+
gr.Markdown(
|
| 188 |
+
"""
|
| 189 |
+
<div class="header">
|
| 190 |
+
<h1>๐ Professional PDF Generator</h1>
|
| 191 |
+
<p><strong>Image UP โข Name DOWN โข HD Quality โข 1-30 Participants</strong></p>
|
| 192 |
+
</div>
|
| 193 |
+
""",
|
| 194 |
+
elem_classes="header"
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
gr.Markdown("""
|
| 198 |
+
### ๐ How to Use:
|
| 199 |
+
1. **Title**: Enter document title
|
| 200 |
+
2. **Names**: Comma-separated (max 30): "John Doe, Jane Smith"
|
| 201 |
+
3. **Images**: Upload matching images
|
| 202 |
+
4. **Layout**: Each page = Large image (UP) + Name/ID (DOWN)
|
| 203 |
+
5. **Output**: Professional PDF with cover page
|
| 204 |
+
""")
|
| 205 |
+
|
| 206 |
+
# Inputs
|
| 207 |
+
with gr.Row():
|
| 208 |
with gr.Column(scale=2):
|
| 209 |
title_input = gr.Textbox(
|
| 210 |
+
label="๐ Document Title *",
|
| 211 |
+
placeholder="Enter your document title...",
|
| 212 |
+
lines=2,
|
| 213 |
+
elem_classes="input-section"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
)
|
| 215 |
+
|
| 216 |
names_input = gr.Textbox(
|
| 217 |
+
label="๐ฅ Names (Comma Separated) *",
|
| 218 |
+
placeholder="John Doe, Jane Smith, Bob Wilson (Max 30)",
|
| 219 |
+
lines=4,
|
| 220 |
+
elem_classes="input-section"
|
| 221 |
)
|
| 222 |
+
|
| 223 |
+
plan_input = gr.Textbox(
|
| 224 |
+
label="๐ Description/Plan (Optional)",
|
| 225 |
+
placeholder="Add description, plan, or notes for cover page...",
|
| 226 |
+
lines=3,
|
| 227 |
+
elem_classes="input-section"
|
| 228 |
)
|
| 229 |
|
| 230 |
with gr.Column(scale=1):
|
| 231 |
+
images_input = gr.File(
|
| 232 |
+
label="๐ผ๏ธ Upload Images *",
|
| 233 |
+
file_count="multiple",
|
| 234 |
+
file_types=[".jpg", ".jpeg", ".png", ".webp"],
|
| 235 |
+
elem_classes="input-section"
|
|
|
|
| 236 |
)
|
|
|
|
|
|
|
| 237 |
|
| 238 |
+
# Controls
|
| 239 |
+
with gr.Row():
|
| 240 |
+
generate_btn = gr.Button("๐ Generate Professional PDF", variant="primary", size="lg")
|
| 241 |
+
clear_btn = gr.Button("๐๏ธ Clear All", variant="secondary")
|
| 242 |
|
| 243 |
+
# Outputs
|
| 244 |
+
with gr.Row(elem_classes="output-zone"):
|
| 245 |
+
pdf_output = gr.File(label="๐ฅ Download Professional PDF")
|
| 246 |
+
|
| 247 |
+
status_output = gr.Markdown("Ready to generate professional PDF...", elem_classes="status-success")
|
| 248 |
+
|
| 249 |
+
# Events
|
| 250 |
+
def clear_all():
|
| 251 |
+
return "", "", "", None, "Form cleared! Ready to create new PDF."
|
| 252 |
|
|
|
|
| 253 |
generate_btn.click(
|
| 254 |
+
fn=generate_pdf,
|
| 255 |
+
inputs=[title_input, plan_input, names_input, images_input],
|
| 256 |
+
outputs=[pdf_output, status_output]
|
| 257 |
)
|
| 258 |
|
| 259 |
clear_btn.click(
|
| 260 |
+
fn=clear_all,
|
| 261 |
+
outputs=[title_input, plan_input, names_input, images_input, status_output]
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
# Real-time name counter
|
| 265 |
+
def count_names(names):
|
| 266 |
+
names_list = [n.strip() for n in names.split(',') if n.strip()]
|
| 267 |
+
count = len(names_list)
|
| 268 |
+
if count > 30:
|
| 269 |
+
return f"โ ๏ธ {count} names (MAX 30 allowed!)"
|
| 270 |
+
return f"โ
{count} names ready"
|
| 271 |
+
|
| 272 |
+
names_input.change(
|
| 273 |
+
fn=count_names,
|
| 274 |
+
inputs=[names_input],
|
| 275 |
+
outputs=[status_output]
|
| 276 |
)
|
| 277 |
|
| 278 |
if __name__ == "__main__":
|