Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from groq import Groq
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
# =========================
|
|
@@ -24,11 +26,9 @@ def generate_roadmap(domain, level, time):
|
|
| 24 |
|
| 25 |
prompt = f"""
|
| 26 |
Create a detailed learning roadmap.
|
| 27 |
-
|
| 28 |
Domain: {domain}
|
| 29 |
Skill Level: {level}
|
| 30 |
Time Available: {time}
|
| 31 |
-
|
| 32 |
Include:
|
| 33 |
- Weekly plan
|
| 34 |
- Resources
|
|
@@ -56,34 +56,66 @@ Include:
|
|
| 56 |
return f"❌ Error: {e}"
|
| 57 |
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# =========================
|
| 60 |
# Custom CSS
|
| 61 |
# =========================
|
| 62 |
custom_css = """
|
| 63 |
-
|
| 64 |
html, body {
|
| 65 |
margin: 0;
|
| 66 |
padding: 0;
|
| 67 |
font-family: Arial, sans-serif;
|
| 68 |
}
|
| 69 |
|
| 70 |
-
|
| 71 |
/* Light Mode */
|
| 72 |
@media (prefers-color-scheme: light) {
|
| 73 |
-
|
| 74 |
html,
|
| 75 |
body,
|
| 76 |
-
.gradio-container
|
| 77 |
-
.app,
|
| 78 |
-
.wrap,
|
| 79 |
-
.container {
|
| 80 |
background: linear-gradient(to right, #dff5e3, #b7e4c7) !important;
|
| 81 |
color: #1a1a1a !important;
|
| 82 |
}
|
| 83 |
|
| 84 |
-
input,
|
| 85 |
-
textarea,
|
| 86 |
-
select {
|
| 87 |
background: #f6fff8 !important;
|
| 88 |
color: #1a1a1a !important;
|
| 89 |
border: 1px solid #9dd9b1 !important;
|
|
@@ -102,25 +134,18 @@ html, body {
|
|
| 102 |
}
|
| 103 |
}
|
| 104 |
|
| 105 |
-
|
| 106 |
/* Dark Mode */
|
| 107 |
@media (prefers-color-scheme: dark) {
|
| 108 |
-
|
| 109 |
html,
|
| 110 |
body,
|
| 111 |
-
.gradio-container
|
| 112 |
-
.app,
|
| 113 |
-
.wrap,
|
| 114 |
-
.container {
|
| 115 |
background: linear-gradient(to right, #667eea, #764ba2) !important;
|
| 116 |
-
color:
|
| 117 |
}
|
| 118 |
|
| 119 |
-
input,
|
| 120 |
-
textarea,
|
| 121 |
-
select {
|
| 122 |
background: #1e1e2f !important;
|
| 123 |
-
color:
|
| 124 |
border: 1px solid #444 !important;
|
| 125 |
}
|
| 126 |
|
|
@@ -135,7 +160,6 @@ html, body {
|
|
| 135 |
background: #6a70e0 !important;
|
| 136 |
}
|
| 137 |
}
|
| 138 |
-
|
| 139 |
"""
|
| 140 |
|
| 141 |
|
|
@@ -164,12 +188,34 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 164 |
|
| 165 |
output = gr.Markdown()
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
generate_btn.click(
|
| 168 |
generate_roadmap,
|
| 169 |
inputs=[domain, level, time],
|
| 170 |
outputs=output
|
| 171 |
)
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
# =========================
|
| 175 |
# Launch
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from groq import Groq
|
| 4 |
+
from reportlab.lib.pagesizes import A4
|
| 5 |
+
from reportlab.pdfgen import canvas
|
| 6 |
|
| 7 |
|
| 8 |
# =========================
|
|
|
|
| 26 |
|
| 27 |
prompt = f"""
|
| 28 |
Create a detailed learning roadmap.
|
|
|
|
| 29 |
Domain: {domain}
|
| 30 |
Skill Level: {level}
|
| 31 |
Time Available: {time}
|
|
|
|
| 32 |
Include:
|
| 33 |
- Weekly plan
|
| 34 |
- Resources
|
|
|
|
| 56 |
return f"❌ Error: {e}"
|
| 57 |
|
| 58 |
|
| 59 |
+
# =========================
|
| 60 |
+
# Generate PDF
|
| 61 |
+
# =========================
|
| 62 |
+
def create_pdf(text):
|
| 63 |
+
|
| 64 |
+
file_path = "/mnt/data/ai_roadmap.pdf"
|
| 65 |
+
|
| 66 |
+
c = canvas.Canvas(file_path, pagesize=A4)
|
| 67 |
+
width, height = A4
|
| 68 |
+
|
| 69 |
+
x = 40
|
| 70 |
+
y = height - 40
|
| 71 |
+
|
| 72 |
+
text_obj = c.beginText(x, y)
|
| 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 |
+
|
| 96 |
+
return file_path
|
| 97 |
+
|
| 98 |
+
|
| 99 |
# =========================
|
| 100 |
# Custom CSS
|
| 101 |
# =========================
|
| 102 |
custom_css = """
|
|
|
|
| 103 |
html, body {
|
| 104 |
margin: 0;
|
| 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;
|
|
|
|
| 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 |
|
|
|
|
| 160 |
background: #6a70e0 !important;
|
| 161 |
}
|
| 162 |
}
|
|
|
|
| 163 |
"""
|
| 164 |
|
| 165 |
|
|
|
|
| 188 |
|
| 189 |
output = gr.Markdown()
|
| 190 |
|
| 191 |
+
pdf_btn = gr.Button("📥 Download as PDF")
|
| 192 |
+
|
| 193 |
+
pdf_file = gr.File(label="Download PDF")
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
# Generate roadmap
|
| 197 |
generate_btn.click(
|
| 198 |
generate_roadmap,
|
| 199 |
inputs=[domain, level, time],
|
| 200 |
outputs=output
|
| 201 |
)
|
| 202 |
|
| 203 |
+
# Generate PDF
|
| 204 |
+
pdf_btn.click(
|
| 205 |
+
create_pdf,
|
| 206 |
+
inputs=output,
|
| 207 |
+
outputs=pdf_file
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
# Footer
|
| 212 |
+
gr.Markdown(
|
| 213 |
+
"""
|
| 214 |
+
---
|
| 215 |
+
🌻 **Made by Kubra** 🌻
|
| 216 |
+
"""
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
|
| 220 |
# =========================
|
| 221 |
# Launch
|