Rammohan0504 commited on
Commit
e175a01
·
verified ·
1 Parent(s): 165fd96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -36
app.py CHANGED
@@ -160,7 +160,7 @@ def save_results_to_pdf(test_results, filename):
160
  return f"Error saving PDF: {str(e)}", None
161
 
162
  # Build health card layout
163
- def build_health_card(profile_image, test_results, summary, patient_name="", patient_age="", patient_gender="", patient_id=""):
164
  from datetime import datetime
165
  current_date = datetime.now().strftime("%B %d, %Y")
166
 
@@ -203,19 +203,13 @@ def build_health_card(profile_image, test_results, summary, patient_name="", pat
203
  </div>
204
 
205
  <div style="display: flex; gap: 15px; justify-content: center; flex-wrap: wrap;">
206
- <button onclick="downloadHealthCard()" style="padding: 12px 24px; background: linear-gradient(135deg, #4caf50, #45a049); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3); transition: all 0.3s;">
207
- 📥 Download Report
208
- </button>
 
 
209
  </div>
210
  </div>
211
- <script>
212
- function downloadHealthCard() {{
213
- const link = document.createElement('a');
214
- link.href = '{pdf_filepath}';
215
- link.download = 'Health_Report.pdf';
216
- link.click();
217
- }}
218
- </script>
219
  """
220
  return html
221
 
@@ -318,7 +312,8 @@ def analyze_face(input_data):
318
  current_patient_details['name'],
319
  current_patient_details['age'],
320
  current_patient_details['gender'],
321
- current_patient_details['id']
 
322
  )
323
 
324
  # Generate PDF and return for download
@@ -333,29 +328,10 @@ def analyze_face(input_data):
333
  return health_card_html, temp_pdf_path
334
 
335
 
336
- # Modified route_inputs function
337
- def route_inputs(mode, image, video, patient_name, patient_age, patient_gender, patient_id):
338
- if mode == "Image" and image is None:
339
- return "<div style='color:red;'>⚠️ Error: No image provided.</div>", None
340
- if mode == "Video" and video is None:
341
- return "<div style='color:red;'>⚠️ Error: No video provided.</div>", None
342
-
343
- # Store patient details globally for use in analyze_face
344
- global current_patient_details
345
- current_patient_details = {
346
- 'name': patient_name,
347
- 'age': patient_age,
348
- 'gender': patient_gender,
349
- 'id': patient_id
350
- }
351
-
352
- health_card_html, pdf_file_path = analyze_face(image if mode == "Image" else video)
353
- return health_card_html, pdf_file_path
354
-
355
-
356
- # Create Gradio interface
357
  with gr.Blocks() as demo:
358
- gr.Markdown("""# 🧠 Face-Based Lab Test AI Report (Video Mode)""")
 
359
  with gr.Row():
360
  with gr.Column():
361
  gr.Markdown("### Patient Information")
@@ -376,7 +352,7 @@ with gr.Blocks() as demo:
376
  result_html = gr.HTML(label="🧪 Health Report Table")
377
  result_pdf = gr.File(label="Download Health Report PDF", interactive=False)
378
 
379
- submit_btn.click(fn=route_inputs,
380
  inputs=[mode_selector, image_input, video_input, patient_name, patient_age, patient_gender, patient_id],
381
  outputs=[result_html, result_pdf])
382
 
 
160
  return f"Error saving PDF: {str(e)}", None
161
 
162
  # Build health card layout
163
+ def build_health_card(profile_image, test_results, summary, patient_name="", patient_age="", patient_gender="", patient_id="", pdf_filepath=""):
164
  from datetime import datetime
165
  current_date = datetime.now().strftime("%B %d, %Y")
166
 
 
203
  </div>
204
 
205
  <div style="display: flex; gap: 15px; justify-content: center; flex-wrap: wrap;">
206
+ <a href="{pdf_filepath}" download="Health_Report.pdf">
207
+ <button style="padding: 12px 24px; background: linear-gradient(135deg, #4caf50, #45a049); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3); transition: all 0.3s;">
208
+ 📥 Download Report
209
+ </button>
210
+ </a>
211
  </div>
212
  </div>
 
 
 
 
 
 
 
 
213
  """
214
  return html
215
 
 
312
  current_patient_details['name'],
313
  current_patient_details['age'],
314
  current_patient_details['gender'],
315
+ current_patient_details['id'],
316
+ pdf_filepath="/tmp/Health_Report.pdf"
317
  )
318
 
319
  # Generate PDF and return for download
 
328
  return health_card_html, temp_pdf_path
329
 
330
 
331
+ # Gradio interface setup
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  with gr.Blocks() as demo:
333
+ gr.Markdown("""# 🧠 Face-Based Lab Test AI Report""")
334
+
335
  with gr.Row():
336
  with gr.Column():
337
  gr.Markdown("### Patient Information")
 
352
  result_html = gr.HTML(label="🧪 Health Report Table")
353
  result_pdf = gr.File(label="Download Health Report PDF", interactive=False)
354
 
355
+ submit_btn.click(fn=analyze_face,
356
  inputs=[mode_selector, image_input, video_input, patient_name, patient_age, patient_gender, patient_id],
357
  outputs=[result_html, result_pdf])
358