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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -23
app.py CHANGED
@@ -47,7 +47,7 @@ Include:
47
  {"role": "user", "content": prompt}
48
  ],
49
 
50
- max_tokens=2500,
51
  temperature=0.7
52
  )
53
 
@@ -61,36 +61,40 @@ Include:
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
 
@@ -98,7 +102,7 @@ def create_pdf(text):
98
 
99
 
100
  # =========================
101
- # Custom CSS
102
  # =========================
103
  custom_css = """
104
  html, body {
@@ -106,11 +110,76 @@ html, body {
106
  padding: 0;
107
  font-family: Arial, sans-serif;
108
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  """
110
 
111
 
112
  # =========================
113
- # UI
114
  # =========================
115
  with gr.Blocks(css=custom_css) as app:
116
 
@@ -132,35 +201,35 @@ with gr.Blocks(css=custom_css) as app:
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
 
157
 
158
- # Footer
159
  gr.Markdown(
160
  """
161
  ---
162
- 🌻 **Made by Kubra** 🌻
163
- Powered by AI β€’ Keep Learning πŸš€
164
  """
165
  )
166
 
 
47
  {"role": "user", "content": prompt}
48
  ],
49
 
50
+ max_tokens=3000,
51
  temperature=0.7
52
  )
53
 
 
61
 
62
 
63
  # =========================
64
+ # Generate PDF
65
  # =========================
66
  def create_pdf(text):
67
 
68
  if not text:
69
  return None
70
 
 
71
  file_path = "ai_roadmap.pdf"
72
 
73
  c = canvas.Canvas(file_path, pagesize=A4)
74
  width, height = A4
75
 
76
+ x = 40
77
+ y = height - 40
78
+
79
+ text_obj = c.beginText(x, y)
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
96
  c.setFont("Helvetica-Bold", 10)
97
+ c.drawCentredString(width / 2, 20, "Made by Kubra 🌻")
98
 
99
  c.save()
100
 
 
102
 
103
 
104
  # =========================
105
+ # Custom CSS (UNCHANGED)
106
  # =========================
107
  custom_css = """
108
  html, body {
 
110
  padding: 0;
111
  font-family: Arial, sans-serif;
112
  }
113
+
114
+ /* Light Mode */
115
+ @media (prefers-color-scheme: light) {
116
+ html,
117
+ body,
118
+ .gradio-container,
119
+ .app,
120
+ .wrap,
121
+ .container {
122
+ background: linear-gradient(to right, #dff5e3, #b7e4c7) !important;
123
+ color: #1a1a1a !important;
124
+ }
125
+
126
+ input,
127
+ textarea,
128
+ select {
129
+ background: #f6fff8 !important;
130
+ color: #1a1a1a !important;
131
+ border: 1px solid #9dd9b1 !important;
132
+ border-radius: 6px;
133
+ }
134
+
135
+ button {
136
+ background: #6fcf97 !important;
137
+ color: #103822 !important;
138
+ border-radius: 8px !important;
139
+ font-weight: 600;
140
+ }
141
+
142
+ button:hover {
143
+ background: #5bbd84 !important;
144
+ }
145
+ }
146
+
147
+ /* Dark Mode */
148
+ @media (prefers-color-scheme: dark) {
149
+ html,
150
+ body,
151
+ .gradio-container,
152
+ .app,
153
+ .wrap,
154
+ .container {
155
+ background: linear-gradient(to right, #667eea, #764ba2) !important;
156
+ color: #ffffff !important;
157
+ }
158
+
159
+ input,
160
+ textarea,
161
+ select {
162
+ background: #1e1e2f !important;
163
+ color: #ffffff !important;
164
+ border: 1px solid #444 !important;
165
+ }
166
+
167
+ button {
168
+ background: #7c83fd !important;
169
+ color: white !important;
170
+ border-radius: 8px !important;
171
+ font-weight: 600;
172
+ }
173
+
174
+ button:hover {
175
+ background: #6a70e0 !important;
176
+ }
177
+ }
178
  """
179
 
180
 
181
  # =========================
182
+ # UI (ORIGINAL)
183
  # =========================
184
  with gr.Blocks(css=custom_css) as app:
185
 
 
201
 
202
  generate_btn = gr.Button("✨ Generate Roadmap")
203
 
204
+ output = gr.Markdown()
205
+ hidden_text = gr.Textbox(visible=False)
206
 
207
  pdf_btn = gr.Button("πŸ“₯ Download as PDF")
208
+
209
  pdf_file = gr.File(label="Download PDF")
210
 
211
 
212
+ # Generate roadmap
213
  generate_btn.click(
214
  generate_roadmap,
215
  inputs=[domain, level, time],
216
+ outputs=[output, hidden_text]
217
  )
218
 
219
+ # Generate PDF
 
220
  pdf_btn.click(
221
  create_pdf,
222
+ inputs=hidden_text,
223
  outputs=pdf_file
224
  )
225
 
226
 
227
+ # Footer (ORIGINAL)
228
  gr.Markdown(
229
  """
230
  ---
231
+ **Made by Kubra** 🌻
232
+
233
  """
234
  )
235