Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import cv2
|
4 |
import numpy as np
|
@@ -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,11 +203,12 @@ 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 |
-
<
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
|
|
211 |
</div>
|
212 |
</div>
|
213 |
<style>
|
@@ -300,6 +301,7 @@ def analyze_face(input_data):
|
|
300 |
build_table("❤️ Vitals",
|
301 |
[("SpO2", spo2, (95, 100)),
|
302 |
("Heart Rate", heart_rate, (60, 100)),
|
|
|
303 |
("Temperature", test_values["Temperature"], (97, 99)),
|
304 |
("BP Systolic", test_values["BP Systolic"], (90, 120)),
|
305 |
("BP Diastolic", test_values["BP Diastolic"], (60, 80))])
|
@@ -319,8 +321,7 @@ 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 |
-
pdf_filepath=""
|
324 |
)
|
325 |
|
326 |
# Generate PDF and return for download
|
@@ -332,20 +333,29 @@ def analyze_face(input_data):
|
|
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)""")
|
@@ -369,7 +379,9 @@ with gr.Blocks() as demo:
|
|
369 |
result_html = gr.HTML(label="🧪 Health Report Table")
|
370 |
result_pdf = gr.File(label="Download Health Report PDF", interactive=False)
|
371 |
|
372 |
-
|
|
|
|
|
373 |
|
374 |
# Launch Gradio for Replit
|
375 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
1 |
+
Import the os module
|
2 |
import gradio as gr
|
3 |
import cv2
|
4 |
import numpy as np
|
|
|
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 |
</div>
|
204 |
|
205 |
<div style="display: flex; gap: 15px; justify-content: center; flex-wrap: wrap;">
|
206 |
+
<button onclick="window.print()" 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 |
+
<button style="padding: 12px 24px; background: linear-gradient(135deg, #2196f3, #1976d2); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);">
|
210 |
+
📞 Find Labs Near Me
|
211 |
+
</button>
|
212 |
</div>
|
213 |
</div>
|
214 |
<style>
|
|
|
301 |
build_table("❤️ Vitals",
|
302 |
[("SpO2", spo2, (95, 100)),
|
303 |
("Heart Rate", heart_rate, (60, 100)),
|
304 |
+
("Respiratory Rate", rr, (12, 20)),
|
305 |
("Temperature", test_values["Temperature"], (97, 99)),
|
306 |
("BP Systolic", test_values["BP Systolic"], (90, 120)),
|
307 |
("BP Diastolic", test_values["BP Diastolic"], (60, 80))])
|
|
|
321 |
current_patient_details['name'],
|
322 |
current_patient_details['age'],
|
323 |
current_patient_details['gender'],
|
324 |
+
current_patient_details['id']
|
|
|
325 |
)
|
326 |
|
327 |
# Generate PDF and return for download
|
|
|
333 |
temp_pdf_path = "/tmp/" + os.path.basename(pdf_filepath)
|
334 |
shutil.copy(pdf_filepath, temp_pdf_path)
|
335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
return health_card_html, temp_pdf_path
|
337 |
|
338 |
+
|
339 |
+
# Modified route_inputs function
|
340 |
+
def route_inputs(mode, image, video, patient_name, patient_age, patient_gender, patient_id):
|
341 |
+
if mode == "Image" and image is None:
|
342 |
+
return "<div style='color:red;'>⚠️ Error: No image provided.</div>", None
|
343 |
+
if mode == "Video" and video is None:
|
344 |
+
return "<div style='color:red;'>⚠️ Error: No video provided.</div>", None
|
345 |
+
|
346 |
+
# Store patient details globally for use in analyze_face
|
347 |
+
global current_patient_details
|
348 |
+
current_patient_details = {
|
349 |
+
'name': patient_name,
|
350 |
+
'age': patient_age,
|
351 |
+
'gender': patient_gender,
|
352 |
+
'id': patient_id
|
353 |
+
}
|
354 |
+
|
355 |
+
health_card_html, pdf_file_path = analyze_face(image if mode == "Image" else video)
|
356 |
+
return health_card_html, pdf_file_path
|
357 |
+
|
358 |
+
|
359 |
# Create Gradio interface
|
360 |
with gr.Blocks() as demo:
|
361 |
gr.Markdown("""# 🧠 Face-Based Lab Test AI Report (Video Mode)""")
|
|
|
379 |
result_html = gr.HTML(label="🧪 Health Report Table")
|
380 |
result_pdf = gr.File(label="Download Health Report PDF", interactive=False)
|
381 |
|
382 |
+
submit_btn.click(fn=route_inputs,
|
383 |
+
inputs=[mode_selector, image_input, video_input, patient_name, patient_age, patient_gender, patient_id],
|
384 |
+
outputs=[result_html, result_pdf])
|
385 |
|
386 |
# Launch Gradio for Replit
|
387 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|