Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
|
@@ -319,7 +319,8 @@ def analyze_face(input_data):
|
|
319 |
current_patient_details['name'],
|
320 |
current_patient_details['age'],
|
321 |
current_patient_details['gender'],
|
322 |
-
current_patient_details['id']
|
|
|
323 |
)
|
324 |
|
325 |
# Generate PDF and return for download
|
@@ -331,29 +332,20 @@ def analyze_face(input_data):
|
|
331 |
temp_pdf_path = "/tmp/" + os.path.basename(pdf_filepath)
|
332 |
shutil.copy(pdf_filepath, temp_pdf_path)
|
333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
return health_card_html, temp_pdf_path
|
335 |
|
336 |
-
|
337 |
-
# Modified route_inputs function
|
338 |
-
def route_inputs(mode, image, video, patient_name, patient_age, patient_gender, patient_id):
|
339 |
-
if mode == "Image" and image is None:
|
340 |
-
return "<div style='color:red;'>⚠️ Error: No image provided.</div>", None
|
341 |
-
if mode == "Video" and video is None:
|
342 |
-
return "<div style='color:red;'>⚠️ Error: No video provided.</div>", None
|
343 |
-
|
344 |
-
# Store patient details globally for use in analyze_face
|
345 |
-
global current_patient_details
|
346 |
-
current_patient_details = {
|
347 |
-
'name': patient_name,
|
348 |
-
'age': patient_age,
|
349 |
-
'gender': patient_gender,
|
350 |
-
'id': patient_id
|
351 |
-
}
|
352 |
-
|
353 |
-
health_card_html, pdf_file_path = analyze_face(image if mode == "Image" else video)
|
354 |
-
return health_card_html, pdf_file_path
|
355 |
-
|
356 |
-
|
357 |
# Create Gradio interface
|
358 |
with gr.Blocks() as demo:
|
359 |
gr.Markdown("""# 🧠 Face-Based Lab Test AI Report (Video Mode)""")
|
|
|
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 |
|
|
|
319 |
current_patient_details['name'],
|
320 |
current_patient_details['age'],
|
321 |
current_patient_details['gender'],
|
322 |
+
current_patient_details['id'],
|
323 |
+
pdf_filepath=""
|
324 |
)
|
325 |
|
326 |
# Generate PDF and return for download
|
|
|
332 |
temp_pdf_path = "/tmp/" + os.path.basename(pdf_filepath)
|
333 |
shutil.copy(pdf_filepath, temp_pdf_path)
|
334 |
|
335 |
+
# Update the HTML to include the link to download the PDF
|
336 |
+
health_card_html = build_health_card(
|
337 |
+
profile_image_base64,
|
338 |
+
test_results,
|
339 |
+
summary,
|
340 |
+
current_patient_details['name'],
|
341 |
+
current_patient_details['age'],
|
342 |
+
current_patient_details['gender'],
|
343 |
+
current_patient_details['id'],
|
344 |
+
pdf_filepath=temp_pdf_path
|
345 |
+
)
|
346 |
+
|
347 |
return health_card_html, temp_pdf_path
|
348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
# Create Gradio interface
|
350 |
with gr.Blocks() as demo:
|
351 |
gr.Markdown("""# 🧠 Face-Based Lab Test AI Report (Video Mode)""")
|