Update app.py
Browse files
app.py
CHANGED
|
@@ -62,7 +62,7 @@ Include:
|
|
| 62 |
|
| 63 |
|
| 64 |
# =========================
|
| 65 |
-
# Generate PDF (FIXED)
|
| 66 |
# =========================
|
| 67 |
def create_pdf(text):
|
| 68 |
|
|
@@ -72,47 +72,59 @@ def create_pdf(text):
|
|
| 72 |
file_path = "ai_roadmap.pdf"
|
| 73 |
|
| 74 |
c = canvas.Canvas(file_path, pagesize=A4)
|
|
|
|
| 75 |
width, height = A4
|
| 76 |
|
| 77 |
margin_x = 40
|
| 78 |
margin_y = 40
|
| 79 |
|
| 80 |
-
max_chars = 90
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
text_obj = c.beginText(margin_x, height - margin_y)
|
| 83 |
-
text_obj.setFont("Helvetica", 11)
|
| 84 |
|
| 85 |
-
# Split into paragraphs
|
| 86 |
paragraphs = text.split("\n\n")
|
| 87 |
|
| 88 |
for para in paragraphs:
|
| 89 |
|
| 90 |
-
lines = []
|
| 91 |
-
|
| 92 |
-
# Handle manual line breaks
|
| 93 |
for raw_line in para.split("\n"):
|
|
|
|
| 94 |
wrapped = textwrap.wrap(raw_line, max_chars)
|
| 95 |
-
if wrapped:
|
| 96 |
-
lines.extend(wrapped)
|
| 97 |
-
else:
|
| 98 |
-
lines.append("")
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
-
c.showPage()
|
| 105 |
-
text_obj = c.beginText(margin_x, height - margin_y)
|
| 106 |
-
text_obj.setFont("Helvetica", 11)
|
| 107 |
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
text_obj.textLine("")
|
| 112 |
|
| 113 |
|
|
|
|
| 114 |
c.drawText(text_obj)
|
| 115 |
|
|
|
|
| 116 |
# Footer
|
| 117 |
c.setFont("Helvetica-Bold", 10)
|
| 118 |
c.drawCentredString(width / 2, 25, "Made by Kubra π»")
|
|
@@ -123,7 +135,7 @@ def create_pdf(text):
|
|
| 123 |
|
| 124 |
|
| 125 |
# =========================
|
| 126 |
-
# Custom CSS
|
| 127 |
# =========================
|
| 128 |
custom_css = """
|
| 129 |
html, body {
|
|
@@ -200,7 +212,7 @@ html, body {
|
|
| 200 |
|
| 201 |
|
| 202 |
# =========================
|
| 203 |
-
# UI
|
| 204 |
# =========================
|
| 205 |
with gr.Blocks(css=custom_css) as app:
|
| 206 |
|
|
@@ -230,14 +242,13 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 230 |
pdf_file = gr.File(label="Download PDF")
|
| 231 |
|
| 232 |
|
| 233 |
-
# Generate roadmap
|
| 234 |
generate_btn.click(
|
| 235 |
generate_roadmap,
|
| 236 |
inputs=[domain, level, time],
|
| 237 |
outputs=[output, hidden_text]
|
| 238 |
)
|
| 239 |
|
| 240 |
-
|
| 241 |
pdf_btn.click(
|
| 242 |
create_pdf,
|
| 243 |
inputs=hidden_text,
|
|
@@ -245,12 +256,10 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 245 |
)
|
| 246 |
|
| 247 |
|
| 248 |
-
# Footer
|
| 249 |
gr.Markdown(
|
| 250 |
"""
|
| 251 |
---
|
| 252 |
-
|
| 253 |
-
Powered by AI β’ Keep Learning π
|
| 254 |
"""
|
| 255 |
)
|
| 256 |
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
# =========================
|
| 65 |
+
# Generate PDF (FULLY FIXED)
|
| 66 |
# =========================
|
| 67 |
def create_pdf(text):
|
| 68 |
|
|
|
|
| 72 |
file_path = "ai_roadmap.pdf"
|
| 73 |
|
| 74 |
c = canvas.Canvas(file_path, pagesize=A4)
|
| 75 |
+
|
| 76 |
width, height = A4
|
| 77 |
|
| 78 |
margin_x = 40
|
| 79 |
margin_y = 40
|
| 80 |
|
| 81 |
+
max_chars = 90
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def new_text_object():
|
| 85 |
+
t = c.beginText(margin_x, height - margin_y)
|
| 86 |
+
t.setFont("Helvetica", 11)
|
| 87 |
+
return t
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
text_obj = new_text_object()
|
| 91 |
|
|
|
|
|
|
|
| 92 |
|
|
|
|
| 93 |
paragraphs = text.split("\n\n")
|
| 94 |
|
| 95 |
for para in paragraphs:
|
| 96 |
|
|
|
|
|
|
|
|
|
|
| 97 |
for raw_line in para.split("\n"):
|
| 98 |
+
|
| 99 |
wrapped = textwrap.wrap(raw_line, max_chars)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
if not wrapped:
|
| 102 |
+
wrapped = [""]
|
| 103 |
+
|
| 104 |
|
| 105 |
+
for line in wrapped:
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
+
# Page break check
|
| 108 |
+
if text_obj.getY() < margin_y:
|
| 109 |
|
| 110 |
+
# Draw current page FIRST
|
| 111 |
+
c.drawText(text_obj)
|
| 112 |
+
c.showPage()
|
| 113 |
+
|
| 114 |
+
# Start new page
|
| 115 |
+
text_obj = new_text_object()
|
| 116 |
+
|
| 117 |
+
text_obj.textLine(line)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
# Space after paragraph
|
| 121 |
text_obj.textLine("")
|
| 122 |
|
| 123 |
|
| 124 |
+
# Draw last page
|
| 125 |
c.drawText(text_obj)
|
| 126 |
|
| 127 |
+
|
| 128 |
# Footer
|
| 129 |
c.setFont("Helvetica-Bold", 10)
|
| 130 |
c.drawCentredString(width / 2, 25, "Made by Kubra π»")
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
# =========================
|
| 138 |
+
# Custom CSS
|
| 139 |
# =========================
|
| 140 |
custom_css = """
|
| 141 |
html, body {
|
|
|
|
| 212 |
|
| 213 |
|
| 214 |
# =========================
|
| 215 |
+
# UI
|
| 216 |
# =========================
|
| 217 |
with gr.Blocks(css=custom_css) as app:
|
| 218 |
|
|
|
|
| 242 |
pdf_file = gr.File(label="Download PDF")
|
| 243 |
|
| 244 |
|
|
|
|
| 245 |
generate_btn.click(
|
| 246 |
generate_roadmap,
|
| 247 |
inputs=[domain, level, time],
|
| 248 |
outputs=[output, hidden_text]
|
| 249 |
)
|
| 250 |
|
| 251 |
+
|
| 252 |
pdf_btn.click(
|
| 253 |
create_pdf,
|
| 254 |
inputs=hidden_text,
|
|
|
|
| 256 |
)
|
| 257 |
|
| 258 |
|
|
|
|
| 259 |
gr.Markdown(
|
| 260 |
"""
|
| 261 |
---
|
| 262 |
+
**Made by Kubra** π»
|
|
|
|
| 263 |
"""
|
| 264 |
)
|
| 265 |
|