Kubratech3 commited on
Commit
a240e27
Β·
verified Β·
1 Parent(s): 1dd2ced

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -79
app.py CHANGED
@@ -22,7 +22,8 @@ client = Groq(api_key=api_key)
22
  def generate_roadmap(domain, level, time):
23
 
24
  if not domain or not time:
25
- return "❌ Please fill all fields.", "❌ Please fill all fields."
 
26
 
27
  prompt = f"""
28
  Create a detailed learning roadmap.
@@ -46,7 +47,7 @@ Include:
46
  {"role": "user", "content": prompt}
47
  ],
48
 
49
- max_tokens=3000,
50
  temperature=0.7
51
  )
52
 
@@ -60,40 +61,36 @@ Include:
60
 
61
 
62
  # =========================
63
- # Generate PDF
64
  # =========================
65
  def create_pdf(text):
66
 
67
  if not text:
68
  return None
69
 
70
- file_path = "/mnt/data/ai_roadmap.pdf"
 
71
 
72
  c = canvas.Canvas(file_path, pagesize=A4)
73
  width, height = A4
74
 
75
- x = 40
76
- y = height - 40
77
-
78
- text_obj = c.beginText(x, y)
79
- text_obj.setFont("Helvetica", 11)
80
 
81
  for line in text.split("\n"):
82
 
83
- if y < 40:
84
  c.showPage()
85
- text_obj = c.beginText(x, height - 40)
86
- text_obj.setFont("Helvetica", 11)
87
- y = height - 40
88
 
89
- text_obj.textLine(line)
90
- y -= 14
91
 
92
- c.drawText(text_obj)
93
 
94
  # Footer
95
  c.setFont("Helvetica-Bold", 10)
96
- c.drawCentredString(width / 2, 20, "Made by Kubra 🌻")
97
 
98
  c.save()
99
 
@@ -109,61 +106,6 @@ html, body {
109
  padding: 0;
110
  font-family: Arial, sans-serif;
111
  }
112
-
113
- /* Light Mode */
114
- @media (prefers-color-scheme: light) {
115
- html,
116
- body,
117
- .gradio-container {
118
- background: linear-gradient(to right, #dff5e3, #b7e4c7) !important;
119
- color: #1a1a1a !important;
120
- }
121
-
122
- input, textarea, select {
123
- background: #f6fff8 !important;
124
- color: #1a1a1a !important;
125
- border: 1px solid #9dd9b1 !important;
126
- border-radius: 6px;
127
- }
128
-
129
- button {
130
- background: #6fcf97 !important;
131
- color: #103822 !important;
132
- border-radius: 8px !important;
133
- font-weight: 600;
134
- }
135
-
136
- button:hover {
137
- background: #5bbd84 !important;
138
- }
139
- }
140
-
141
- /* Dark Mode */
142
- @media (prefers-color-scheme: dark) {
143
- html,
144
- body,
145
- .gradio-container {
146
- background: linear-gradient(to right, #667eea, #764ba2) !important;
147
- color: white !important;
148
- }
149
-
150
- input, textarea, select {
151
- background: #1e1e2f !important;
152
- color: white !important;
153
- border: 1px solid #444 !important;
154
- }
155
-
156
- button {
157
- background: #7c83fd !important;
158
- color: white !important;
159
- border-radius: 8px !important;
160
- font-weight: 600;
161
- }
162
-
163
- button:hover {
164
- background: #6a70e0 !important;
165
- }
166
- }
167
  """
168
 
169
 
@@ -190,25 +132,25 @@ with gr.Blocks(css=custom_css) as app:
190
 
191
  generate_btn = gr.Button("✨ Generate Roadmap")
192
 
193
- output = gr.Markdown()
194
- hidden_text = gr.Textbox(visible=False)
195
 
196
  pdf_btn = gr.Button("πŸ“₯ Download as PDF")
197
-
198
  pdf_file = gr.File(label="Download PDF")
199
 
200
 
201
- # Generate roadmap
202
  generate_btn.click(
203
  generate_roadmap,
204
  inputs=[domain, level, time],
205
- outputs=[output, hidden_text]
206
  )
207
 
208
- # Generate PDF
 
209
  pdf_btn.click(
210
  create_pdf,
211
- inputs=hidden_text,
212
  outputs=pdf_file
213
  )
214
 
 
22
  def generate_roadmap(domain, level, time):
23
 
24
  if not domain or not time:
25
+ msg = "❌ Please fill all fields."
26
+ return msg, msg
27
 
28
  prompt = f"""
29
  Create a detailed learning roadmap.
 
47
  {"role": "user", "content": prompt}
48
  ],
49
 
50
+ max_tokens=2500,
51
  temperature=0.7
52
  )
53
 
 
61
 
62
 
63
  # =========================
64
+ # Generate PDF (HF SAFE)
65
  # =========================
66
  def create_pdf(text):
67
 
68
  if not text:
69
  return None
70
 
71
+ # HF writable path
72
+ file_path = "ai_roadmap.pdf"
73
 
74
  c = canvas.Canvas(file_path, pagesize=A4)
75
  width, height = A4
76
 
77
+ text_object = c.beginText(40, height - 40)
78
+ text_object.setFont("Helvetica", 11)
 
 
 
79
 
80
  for line in text.split("\n"):
81
 
82
+ if text_object.getY() < 40:
83
  c.showPage()
84
+ text_object = c.beginText(40, height - 40)
85
+ text_object.setFont("Helvetica", 11)
 
86
 
87
+ text_object.textLine(line)
 
88
 
89
+ c.drawText(text_object)
90
 
91
  # Footer
92
  c.setFont("Helvetica-Bold", 10)
93
+ c.drawCentredString(width / 2, 25, "Made by Kubra 🌻")
94
 
95
  c.save()
96
 
 
106
  padding: 0;
107
  font-family: Arial, sans-serif;
108
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  """
110
 
111
 
 
132
 
133
  generate_btn = gr.Button("✨ Generate Roadmap")
134
 
135
+ output_md = gr.Markdown()
136
+ output_text = gr.Textbox(visible=False)
137
 
138
  pdf_btn = gr.Button("πŸ“₯ Download as PDF")
 
139
  pdf_file = gr.File(label="Download PDF")
140
 
141
 
142
+ # Generate
143
  generate_btn.click(
144
  generate_roadmap,
145
  inputs=[domain, level, time],
146
+ outputs=[output_md, output_text]
147
  )
148
 
149
+
150
+ # PDF
151
  pdf_btn.click(
152
  create_pdf,
153
+ inputs=output_text,
154
  outputs=pdf_file
155
  )
156