Rammohan0504 commited on
Commit
e87e634
·
verified ·
1 Parent(s): 9ea6667

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -31
app.py CHANGED
@@ -302,6 +302,13 @@ def analyze_face(input_data):
302
  _, buffer = cv2.imencode('.png', frame_rgb)
303
  profile_image_base64 = base64.b64encode(buffer).decode('utf-8')
304
 
 
 
 
 
 
 
 
305
  # Use global patient details
306
  global current_patient_details
307
  health_card_html = build_health_card(
@@ -311,39 +318,11 @@ def analyze_face(input_data):
311
  current_patient_details['name'],
312
  current_patient_details['age'],
313
  current_patient_details['gender'],
314
- current_patient_details['id']
 
315
  )
316
 
317
- # Generate PDF and return for download
318
- pdf_filename = f"Health_Report_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.pdf"
319
- pdf_result, pdf_filepath = save_results_to_pdf(test_results, pdf_filename)
320
-
321
- if pdf_filepath:
322
- # Copy the PDF to a temporary directory for Gradio to serve it
323
- temp_pdf_path = "/tmp/" + os.path.basename(pdf_filepath)
324
- shutil.copy(pdf_filepath, temp_pdf_path)
325
-
326
- return health_card_html, temp_pdf_path
327
-
328
-
329
- # Modified route_inputs function
330
- def route_inputs(mode, image, video, patient_name, patient_age, patient_gender, patient_id):
331
- if mode == "Image" and image is None:
332
- return "<div style='color:red;'>⚠️ Error: No image provided.</div>", None
333
- if mode == "Video" and video is None:
334
- return "<div style='color:red;'>⚠️ Error: No video provided.</div>", None
335
-
336
- # Store patient details globally for use in analyze_face
337
- global current_patient_details
338
- current_patient_details = {
339
- 'name': patient_name,
340
- 'age': patient_age,
341
- 'gender': patient_gender,
342
- 'id': patient_id
343
- }
344
-
345
- health_card_html, pdf_file_path = analyze_face(image if mode == "Image" else video)
346
- return health_card_html, pdf_file_path
347
 
348
 
349
  # Create Gradio interface
 
302
  _, buffer = cv2.imencode('.png', frame_rgb)
303
  profile_image_base64 = base64.b64encode(buffer).decode('utf-8')
304
 
305
+ # Create a temporary file path for the PDF
306
+ pdf_filename = f"Health_Report_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.pdf"
307
+ pdf_filepath = f"/tmp/{pdf_filename}"
308
+
309
+ # Save the PDF
310
+ pdf_result, _ = save_results_to_pdf(test_results, pdf_filepath)
311
+
312
  # Use global patient details
313
  global current_patient_details
314
  health_card_html = build_health_card(
 
318
  current_patient_details['name'],
319
  current_patient_details['age'],
320
  current_patient_details['gender'],
321
+ current_patient_details['id'],
322
+ pdf_filepath=pdf_filepath
323
  )
324
 
325
+ return health_card_html, pdf_filepath
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
 
328
  # Create Gradio interface