Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
|
@@ -6,8 +7,8 @@ from sklearn.linear_model import LinearRegression
|
|
| 6 |
import random
|
| 7 |
import base64
|
| 8 |
import joblib
|
| 9 |
-
import shutil
|
| 10 |
from datetime import datetime
|
|
|
|
| 11 |
from reportlab.lib.pagesizes import letter
|
| 12 |
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
|
| 13 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
|
@@ -20,7 +21,6 @@ face_mesh = mp_face_mesh.FaceMesh(static_image_mode=True,
|
|
| 20 |
refine_landmarks=True,
|
| 21 |
min_detection_confidence=0.5)
|
| 22 |
|
| 23 |
-
|
| 24 |
# Functions for feature extraction
|
| 25 |
def extract_features(image, landmarks):
|
| 26 |
red_channel = image[:, :, 2]
|
|
@@ -242,7 +242,6 @@ def analyze_face(input_data):
|
|
| 242 |
# Resize image to reduce processing time
|
| 243 |
frame = cv2.resize(frame, (640, 480)) # Adjust resolution for Replit
|
| 244 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 245 |
-
# Provide image dimensions to mediapipe to avoid NORM_RECT warning
|
| 246 |
result = face_mesh.process(frame_rgb)
|
| 247 |
if not result.multi_face_landmarks:
|
| 248 |
return "<div style='color:red;'>⚠️ Error: Face not detected.</div>", None
|
|
@@ -379,12 +378,11 @@ with gr.Blocks() as demo:
|
|
| 379 |
submit_btn = gr.Button("🔍 Analyze")
|
| 380 |
with gr.Column():
|
| 381 |
result_html = gr.HTML(label="🧪 Health Report Table")
|
| 382 |
-
|
| 383 |
-
result_pdf = gr.File(label="Download Health Report PDF")
|
| 384 |
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
|
| 389 |
# Launch Gradio for Replit
|
| 390 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
+
import os # Import the os module
|
| 2 |
import gradio as gr
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
|
|
|
| 7 |
import random
|
| 8 |
import base64
|
| 9 |
import joblib
|
|
|
|
| 10 |
from datetime import datetime
|
| 11 |
+
import shutil
|
| 12 |
from reportlab.lib.pagesizes import letter
|
| 13 |
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
|
| 14 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
|
|
|
| 21 |
refine_landmarks=True,
|
| 22 |
min_detection_confidence=0.5)
|
| 23 |
|
|
|
|
| 24 |
# Functions for feature extraction
|
| 25 |
def extract_features(image, landmarks):
|
| 26 |
red_channel = image[:, :, 2]
|
|
|
|
| 242 |
# Resize image to reduce processing time
|
| 243 |
frame = cv2.resize(frame, (640, 480)) # Adjust resolution for Replit
|
| 244 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
|
|
|
| 245 |
result = face_mesh.process(frame_rgb)
|
| 246 |
if not result.multi_face_landmarks:
|
| 247 |
return "<div style='color:red;'>⚠️ Error: Face not detected.</div>", None
|
|
|
|
| 378 |
submit_btn = gr.Button("🔍 Analyze")
|
| 379 |
with gr.Column():
|
| 380 |
result_html = gr.HTML(label="🧪 Health Report Table")
|
| 381 |
+
result_pdf = gr.File(label="Download Health Report PDF", interactive=False)
|
|
|
|
| 382 |
|
| 383 |
+
submit_btn.click(fn=route_inputs,
|
| 384 |
+
inputs=[mode_selector, image_input, video_input, patient_name, patient_age, patient_gender, patient_id],
|
| 385 |
+
outputs=[result_html, result_pdf])
|
| 386 |
|
| 387 |
# Launch Gradio for Replit
|
| 388 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|