Rammohan0504 commited on
Commit
ff02b4a
·
verified ·
1 Parent(s): 750e323

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -17,6 +17,8 @@ import glob
17
  def cleanup_temp_files():
18
  for temp_file in glob.glob("/tmp/Health_Report_*.pdf"):
19
  os.remove(temp_file)
 
 
20
  atexit.register(cleanup_temp_files)
21
 
22
  # Initialize the face mesh model
@@ -188,10 +190,15 @@ def save_results_to_pdf(profile_image_base64, test_results, summary, patient_nam
188
  </html>
189
  """
190
 
 
 
 
191
  # Save HTML to a temporary file
192
  html_temp_path = "/tmp/health_card.html"
 
193
  with open(html_temp_path, "w", encoding="utf-8") as f:
194
  f.write(health_card_html)
 
195
 
196
  # Convert HTML to PDF using pdfkit
197
  pdfkit.from_file(html_temp_path, filename, options={"quiet": ""})
@@ -207,7 +214,12 @@ def save_results_to_pdf(profile_image_base64, test_results, summary, patient_nam
207
  return "Error: PDF file not accessible.", None
208
  except Exception as e:
209
  print(f"Error saving PDF: {str(e)}") # Debug log
210
- return f"Error saving PDF: {str(e)}", None
 
 
 
 
 
211
 
212
  # Build health card layout
213
  def build_health_card(profile_image, test_results, summary, pdf_filepath, patient_name="", patient_age="", patient_gender="", patient_id=""):
 
17
  def cleanup_temp_files():
18
  for temp_file in glob.glob("/tmp/Health_Report_*.pdf"):
19
  os.remove(temp_file)
20
+ for temp_file in glob.glob("/tmp/health_card.html"):
21
+ os.remove(temp_file)
22
  atexit.register(cleanup_temp_files)
23
 
24
  # Initialize the face mesh model
 
190
  </html>
191
  """
192
 
193
+ # Debug: Print HTML length
194
+ print(f"HTML generated, length: {len(health_card_html)}")
195
+
196
  # Save HTML to a temporary file
197
  html_temp_path = "/tmp/health_card.html"
198
+ os.makedirs(os.path.dirname(html_temp_path), exist_ok=True)
199
  with open(html_temp_path, "w", encoding="utf-8") as f:
200
  f.write(health_card_html)
201
+ print(f"HTML saved to: {html_temp_path}")
202
 
203
  # Convert HTML to PDF using pdfkit
204
  pdfkit.from_file(html_temp_path, filename, options={"quiet": ""})
 
214
  return "Error: PDF file not accessible.", None
215
  except Exception as e:
216
  print(f"Error saving PDF: {str(e)}") # Debug log
217
+ # Fallback: Save HTML for manual conversion
218
+ html_fallback_path = "/tmp/health_card_fallback.html"
219
+ with open(html_fallback_path, "w", encoding="utf-8") as f:
220
+ f.write(health_card_html)
221
+ print(f"Fallback HTML saved to: {html_fallback_path}")
222
+ return f"Error saving PDF: {str(e)}. Fallback HTML saved at {html_fallback_path}", None
223
 
224
  # Build health card layout
225
  def build_health_card(profile_image, test_results, summary, pdf_filepath, patient_name="", patient_age="", patient_gender="", patient_id=""):