Update app.py
Browse files
app.py
CHANGED
|
@@ -50,10 +50,14 @@ Include:
|
|
| 50 |
temperature=0.7
|
| 51 |
)
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
except Exception as e:
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
# =========================
|
|
@@ -61,6 +65,9 @@ Include:
|
|
| 61 |
# =========================
|
| 62 |
def create_pdf(text):
|
| 63 |
|
|
|
|
|
|
|
|
|
|
| 64 |
file_path = "/mnt/data/ai_roadmap.pdf"
|
| 65 |
|
| 66 |
c = canvas.Canvas(file_path, pagesize=A4)
|
|
@@ -73,23 +80,21 @@ def create_pdf(text):
|
|
| 73 |
text_obj.setFont("Helvetica", 11)
|
| 74 |
|
| 75 |
for line in text.split("\n"):
|
|
|
|
| 76 |
if y < 40:
|
| 77 |
c.showPage()
|
| 78 |
text_obj = c.beginText(x, height - 40)
|
| 79 |
text_obj.setFont("Helvetica", 11)
|
|
|
|
| 80 |
|
| 81 |
text_obj.textLine(line)
|
| 82 |
y -= 14
|
| 83 |
|
| 84 |
c.drawText(text_obj)
|
| 85 |
|
| 86 |
-
# Footer
|
| 87 |
c.setFont("Helvetica-Bold", 10)
|
| 88 |
-
c.drawCentredString(
|
| 89 |
-
width / 2,
|
| 90 |
-
20,
|
| 91 |
-
"Made by Kubra π»"
|
| 92 |
-
)
|
| 93 |
|
| 94 |
c.save()
|
| 95 |
|
|
@@ -105,61 +110,6 @@ html, body {
|
|
| 105 |
padding: 0;
|
| 106 |
font-family: Arial, sans-serif;
|
| 107 |
}
|
| 108 |
-
|
| 109 |
-
/* Light Mode */
|
| 110 |
-
@media (prefers-color-scheme: light) {
|
| 111 |
-
html,
|
| 112 |
-
body,
|
| 113 |
-
.gradio-container {
|
| 114 |
-
background: linear-gradient(to right, #dff5e3, #b7e4c7) !important;
|
| 115 |
-
color: #1a1a1a !important;
|
| 116 |
-
}
|
| 117 |
-
|
| 118 |
-
input, textarea, select {
|
| 119 |
-
background: #f6fff8 !important;
|
| 120 |
-
color: #1a1a1a !important;
|
| 121 |
-
border: 1px solid #9dd9b1 !important;
|
| 122 |
-
border-radius: 6px;
|
| 123 |
-
}
|
| 124 |
-
|
| 125 |
-
button {
|
| 126 |
-
background: #6fcf97 !important;
|
| 127 |
-
color: #103822 !important;
|
| 128 |
-
border-radius: 8px !important;
|
| 129 |
-
font-weight: 600;
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
button:hover {
|
| 133 |
-
background: #5bbd84 !important;
|
| 134 |
-
}
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
/* Dark Mode */
|
| 138 |
-
@media (prefers-color-scheme: dark) {
|
| 139 |
-
html,
|
| 140 |
-
body,
|
| 141 |
-
.gradio-container {
|
| 142 |
-
background: linear-gradient(to right, #667eea, #764ba2) !important;
|
| 143 |
-
color: white !important;
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
input, textarea, select {
|
| 147 |
-
background: #1e1e2f !important;
|
| 148 |
-
color: white !important;
|
| 149 |
-
border: 1px solid #444 !important;
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
button {
|
| 153 |
-
background: #7c83fd !important;
|
| 154 |
-
color: white !important;
|
| 155 |
-
border-radius: 8px !important;
|
| 156 |
-
font-weight: 600;
|
| 157 |
-
}
|
| 158 |
-
|
| 159 |
-
button:hover {
|
| 160 |
-
background: #6a70e0 !important;
|
| 161 |
-
}
|
| 162 |
-
}
|
| 163 |
"""
|
| 164 |
|
| 165 |
|
|
@@ -186,10 +136,10 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 186 |
|
| 187 |
generate_btn = gr.Button("β¨ Generate Roadmap")
|
| 188 |
|
| 189 |
-
|
|
|
|
| 190 |
|
| 191 |
pdf_btn = gr.Button("π₯ Download as PDF")
|
| 192 |
-
|
| 193 |
pdf_file = gr.File(label="Download PDF")
|
| 194 |
|
| 195 |
|
|
@@ -197,13 +147,14 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 197 |
generate_btn.click(
|
| 198 |
generate_roadmap,
|
| 199 |
inputs=[domain, level, time],
|
| 200 |
-
outputs=
|
| 201 |
)
|
| 202 |
|
|
|
|
| 203 |
# Generate PDF
|
| 204 |
pdf_btn.click(
|
| 205 |
create_pdf,
|
| 206 |
-
inputs=
|
| 207 |
outputs=pdf_file
|
| 208 |
)
|
| 209 |
|
|
@@ -212,7 +163,8 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 212 |
gr.Markdown(
|
| 213 |
"""
|
| 214 |
---
|
| 215 |
-
|
|
|
|
| 216 |
"""
|
| 217 |
)
|
| 218 |
|
|
|
|
| 50 |
temperature=0.7
|
| 51 |
)
|
| 52 |
|
| 53 |
+
result = response.choices[0].message.content
|
| 54 |
+
|
| 55 |
+
# Return for display + for PDF
|
| 56 |
+
return result, result
|
| 57 |
|
| 58 |
except Exception as e:
|
| 59 |
+
err = f"β Error: {e}"
|
| 60 |
+
return err, err
|
| 61 |
|
| 62 |
|
| 63 |
# =========================
|
|
|
|
| 65 |
# =========================
|
| 66 |
def create_pdf(text):
|
| 67 |
|
| 68 |
+
if not text:
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
file_path = "/mnt/data/ai_roadmap.pdf"
|
| 72 |
|
| 73 |
c = canvas.Canvas(file_path, pagesize=A4)
|
|
|
|
| 80 |
text_obj.setFont("Helvetica", 11)
|
| 81 |
|
| 82 |
for line in text.split("\n"):
|
| 83 |
+
|
| 84 |
if y < 40:
|
| 85 |
c.showPage()
|
| 86 |
text_obj = c.beginText(x, height - 40)
|
| 87 |
text_obj.setFont("Helvetica", 11)
|
| 88 |
+
y = height - 40
|
| 89 |
|
| 90 |
text_obj.textLine(line)
|
| 91 |
y -= 14
|
| 92 |
|
| 93 |
c.drawText(text_obj)
|
| 94 |
|
| 95 |
+
# Footer in PDF
|
| 96 |
c.setFont("Helvetica-Bold", 10)
|
| 97 |
+
c.drawCentredString(width / 2, 20, "Made by Kubra π»")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
c.save()
|
| 100 |
|
|
|
|
| 110 |
padding: 0;
|
| 111 |
font-family: Arial, sans-serif;
|
| 112 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
"""
|
| 114 |
|
| 115 |
|
|
|
|
| 136 |
|
| 137 |
generate_btn = gr.Button("β¨ Generate Roadmap")
|
| 138 |
|
| 139 |
+
output_md = gr.Markdown()
|
| 140 |
+
output_text = gr.Textbox(visible=False) # Hidden for PDF
|
| 141 |
|
| 142 |
pdf_btn = gr.Button("π₯ Download as PDF")
|
|
|
|
| 143 |
pdf_file = gr.File(label="Download PDF")
|
| 144 |
|
| 145 |
|
|
|
|
| 147 |
generate_btn.click(
|
| 148 |
generate_roadmap,
|
| 149 |
inputs=[domain, level, time],
|
| 150 |
+
outputs=[output_md, output_text]
|
| 151 |
)
|
| 152 |
|
| 153 |
+
|
| 154 |
# Generate PDF
|
| 155 |
pdf_btn.click(
|
| 156 |
create_pdf,
|
| 157 |
+
inputs=output_text,
|
| 158 |
outputs=pdf_file
|
| 159 |
)
|
| 160 |
|
|
|
|
| 163 |
gr.Markdown(
|
| 164 |
"""
|
| 165 |
---
|
| 166 |
+
**Made by Kubra** π»
|
| 167 |
+
|
| 168 |
"""
|
| 169 |
)
|
| 170 |
|