Dineshpopuri commited on
Commit
37b77cd
·
verified ·
1 Parent(s): df24de1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -7
app.py CHANGED
@@ -156,23 +156,63 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
156
  # Generate PDF report with signature slots using in-memory buffer
157
  def generate_pdf(score, checklist_summary, missing_summary, status):
158
  try:
 
 
 
 
 
 
159
  # Use an in-memory buffer instead of writing to disk
160
  buffer = io.BytesIO()
161
  c = canvas.Canvas(buffer, pagesize=letter)
 
 
162
  c.setFont("Helvetica-Bold", 16)
163
  c.drawString(50, 750, "Project Closure Readiness Report")
 
 
164
  c.setFont("Helvetica", 12)
165
  c.drawString(50, 720, f"Readiness Score: {score}%")
166
  c.drawString(50, 700, f"Status: {status}")
167
  c.drawString(50, 680, "Checklist Summary:")
 
 
168
  y = 660
 
169
  for line in checklist_summary.split("\n"):
 
 
 
 
170
  c.drawString(50, y, line)
171
  y -= 20
172
- c.drawString(50, y-20, "Missing Items:")
173
- c.drawString(50, y-40, missing_summary)
174
- c.drawString(50, y-80, "Stakeholder Signature: ____________________")
175
- c.drawString(50, y-100, "Date: ____________________")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  c.save()
177
  buffer.seek(0)
178
  return buffer, "readiness_report.pdf"
@@ -197,9 +237,7 @@ with gr.Blocks(css="""progress { background-color: #f0f0f0; } .red { background-
197
  submit_btn = gr.Button("Evaluate Readiness")
198
  with gr.Column(scale=3):
199
  score_output = gr.Number(label="Readiness Score (%)")
200
- progress_output = gr.HTML(
201
- label="Alert Indicator: Progress"
202
- )
203
  gr.Markdown("Color-coded readiness: Red (<70%), Yellow (70-90%), Green (>90%)")
204
  status_output = gr.Textbox(label="Overall Status")
205
  with gr.Group():
 
156
  # Generate PDF report with signature slots using in-memory buffer
157
  def generate_pdf(score, checklist_summary, missing_summary, status):
158
  try:
159
+ # Sanitize inputs to ensure they are strings and handle None
160
+ score = str(float(score)) if score is not None else "0"
161
+ checklist_summary = str(checklist_summary) if checklist_summary is not None else ""
162
+ missing_summary = str(missing_summary) if missing_summary is not None else ""
163
+ status = str(status) if status is not None else ""
164
+
165
  # Use an in-memory buffer instead of writing to disk
166
  buffer = io.BytesIO()
167
  c = canvas.Canvas(buffer, pagesize=letter)
168
+
169
+ # Set initial font and draw title
170
  c.setFont("Helvetica-Bold", 16)
171
  c.drawString(50, 750, "Project Closure Readiness Report")
172
+
173
+ # Draw basic fields
174
  c.setFont("Helvetica", 12)
175
  c.drawString(50, 720, f"Readiness Score: {score}%")
176
  c.drawString(50, 700, f"Status: {status}")
177
  c.drawString(50, 680, "Checklist Summary:")
178
+
179
+ # Draw checklist summary with Y-position overflow handling
180
  y = 660
181
+ BOTTOM_MARGIN = 50 # Minimum Y position before creating a new page
182
  for line in checklist_summary.split("\n"):
183
+ if y < BOTTOM_MARGIN:
184
+ c.showPage() # Create a new page
185
+ c.setFont("Helvetica", 12) # Reset font for new page
186
+ y = 750 # Reset Y position
187
  c.drawString(50, y, line)
188
  y -= 20
189
+
190
+ # Draw remaining fields with Y-position checks
191
+ if y < BOTTOM_MARGIN:
192
+ c.showPage()
193
+ c.setFont("Helvetica", 12)
194
+ y = 750
195
+ c.drawString(50, y - 20, "Missing Items:")
196
+
197
+ if y - 40 < BOTTOM_MARGIN:
198
+ c.showPage()
199
+ c.setFont("Helvetica", 12)
200
+ y = 750
201
+ c.drawString(50, y - 40, missing_summary)
202
+
203
+ if y - 80 < BOTTOM_MARGIN:
204
+ c.showPage()
205
+ c.setFont("Helvetica", 12)
206
+ y = 750
207
+ c.drawString(50, y - 80, "Stakeholder Signature: ____________________")
208
+
209
+ if y - 100 < BOTTOM_MARGIN:
210
+ c.showPage()
211
+ c.setFont("Helvetica", 12)
212
+ y = 750
213
+ c.drawString(50, y - 100, "Date: ____________________")
214
+
215
+ # Finalize the PDF
216
  c.save()
217
  buffer.seek(0)
218
  return buffer, "readiness_report.pdf"
 
237
  submit_btn = gr.Button("Evaluate Readiness")
238
  with gr.Column(scale=3):
239
  score_output = gr.Number(label="Readiness Score (%)")
240
+ progress_output = gr.HTML(label="Alert Indicator: Progress")
 
 
241
  gr.Markdown("Color-coded readiness: Red (<70%), Yellow (70-90%), Green (>90%)")
242
  status_output = gr.Textbox(label="Overall Status")
243
  with gr.Group():