Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,10 @@ import tempfile
|
|
| 6 |
import os
|
| 7 |
import math
|
| 8 |
|
| 9 |
-
# إعداد Mediapipe Pose
|
| 10 |
mp_pose = mp.solutions.pose
|
| 11 |
pose = mp_pose.Pose(static_image_mode=False, min_detection_confidence=0.8, model_complexity=2)
|
| 12 |
|
| 13 |
-
def _dist(p1, p2):
|
| 14 |
return math.hypot(p1[0]-p2[0], p1[1]-p2[1])
|
| 15 |
|
| 16 |
def _angle(a, b, c):
|
|
@@ -40,7 +39,6 @@ def analyze_gait(video_file):
|
|
| 40 |
if video_file is None:
|
| 41 |
return "<div style='direction:rtl;text-align:right'>❌ يرجى رفع فيديو أولًا.</div>", "<div></div>"
|
| 42 |
|
| 43 |
-
# حفظ مؤقت للفيديو
|
| 44 |
if hasattr(video_file, "name"):
|
| 45 |
video_path = video_file.name
|
| 46 |
else:
|
|
@@ -158,19 +156,10 @@ def analyze_gait(video_file):
|
|
| 158 |
level, color, desc = "🟢 طبيعية", "#2e7d32", "المشية ضمن النطاق السليم."
|
| 159 |
booking = ""
|
| 160 |
|
| 161 |
-
if red_flags >= 3 and base_ratio > 0.25:
|
| 162 |
-
condition = "قدم شاركوت (Charcot Foot)"
|
| 163 |
-
elif min(avg_Lc, avg_Rc) < 4 or low_ratio_L > 0.4 or low_ratio_R > 0.4:
|
| 164 |
-
condition = "ضعف العضلة الظنبوبية (Foot Drop)"
|
| 165 |
-
elif var_clear > 8 or sym_angle > 15:
|
| 166 |
-
condition = "اعتلال الأعصاب المحيطية / السكري"
|
| 167 |
-
else:
|
| 168 |
-
condition = "خلل بسيط غير محدد"
|
| 169 |
-
|
| 170 |
html = f"""
|
| 171 |
<div style='direction:rtl;text-align:right;color:{color};font-weight:700;font-size:18px'>{level}</div>
|
| 172 |
<div>📍 الجانب المتأثر: <b>{side}</b></div>
|
| 173 |
-
<div>🩺 الحالة المحتملة: <b>
|
| 174 |
<div>📊 درجة الخطورة: <b>{score:.1f}/10</b></div>
|
| 175 |
<div>{desc}</div>
|
| 176 |
{booking}
|
|
@@ -178,7 +167,6 @@ def analyze_gait(video_file):
|
|
| 178 |
"""
|
| 179 |
return html, _gauge_html(norm_score)
|
| 180 |
|
| 181 |
-
# تعليمات التصوير
|
| 182 |
instructions = """
|
| 183 |
<div style='direction:rtl;text-align:right'>
|
| 184 |
<h3>🎥 تعليمات التصوير لضمان دقة التحليل:</h3>
|
|
@@ -193,35 +181,32 @@ instructions = """
|
|
| 193 |
</div>
|
| 194 |
"""
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
gr.Markdown("<h2 style='direction:rtl;text-align:right'>🩺 نظام تحليل المشية العصبية – الإصدار 8.2</h2>")
|
| 199 |
gr.HTML(instructions)
|
| 200 |
with gr.Row():
|
| 201 |
with gr.Column(scale=1):
|
| 202 |
video_in = gr.File(label="📂 اختر فيديو المشي", file_types=[".mp4", ".avi", ".mov"], type="binary")
|
| 203 |
-
analyze_btn = gr.Button("🔍 بدء التحليل"
|
| 204 |
with gr.Column(scale=1):
|
| 205 |
gauge = gr.HTML("<div></div>")
|
| 206 |
out_html = gr.HTML("<i style='direction:rtl;text-align:right'>النتيجة ستظهر هنا بعد التحليل...</i>")
|
| 207 |
analyze_btn.click(fn=analyze_gait, inputs=[video_in], outputs=[out_html, gauge])
|
| 208 |
|
| 209 |
-
# تنسيق CSS موحد للأزرار باللون الأخضر
|
| 210 |
-
demo.load(None, None, None, _js="""
|
| 211 |
-
document.querySelectorAll('button, .btn').forEach(btn => {
|
| 212 |
-
btn.style.backgroundColor = '#2e7d32';
|
| 213 |
-
btn.style.color = 'white';
|
| 214 |
-
btn.style.borderRadius = '8px';
|
| 215 |
-
btn.style.fontWeight = '600';
|
| 216 |
-
});
|
| 217 |
-
""")
|
| 218 |
-
|
| 219 |
if __name__ == "__main__":
|
| 220 |
demo.launch()
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
-
|
| 226 |
|
| 227 |
|
|
|
|
| 6 |
import os
|
| 7 |
import math
|
| 8 |
|
|
|
|
| 9 |
mp_pose = mp.solutions.pose
|
| 10 |
pose = mp_pose.Pose(static_image_mode=False, min_detection_confidence=0.8, model_complexity=2)
|
| 11 |
|
| 12 |
+
def _dist(p1, p2):
|
| 13 |
return math.hypot(p1[0]-p2[0], p1[1]-p2[1])
|
| 14 |
|
| 15 |
def _angle(a, b, c):
|
|
|
|
| 39 |
if video_file is None:
|
| 40 |
return "<div style='direction:rtl;text-align:right'>❌ يرجى رفع فيديو أولًا.</div>", "<div></div>"
|
| 41 |
|
|
|
|
| 42 |
if hasattr(video_file, "name"):
|
| 43 |
video_path = video_file.name
|
| 44 |
else:
|
|
|
|
| 156 |
level, color, desc = "🟢 طبيعية", "#2e7d32", "المشية ضمن النطاق السليم."
|
| 157 |
booking = ""
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
html = f"""
|
| 160 |
<div style='direction:rtl;text-align:right;color:{color};font-weight:700;font-size:18px'>{level}</div>
|
| 161 |
<div>📍 الجانب المتأثر: <b>{side}</b></div>
|
| 162 |
+
<div>🩺 الحالة المحتملة: <b>غير محددة</b></div>
|
| 163 |
<div>📊 درجة الخطورة: <b>{score:.1f}/10</b></div>
|
| 164 |
<div>{desc}</div>
|
| 165 |
{booking}
|
|
|
|
| 167 |
"""
|
| 168 |
return html, _gauge_html(norm_score)
|
| 169 |
|
|
|
|
| 170 |
instructions = """
|
| 171 |
<div style='direction:rtl;text-align:right'>
|
| 172 |
<h3>🎥 تعليمات التصوير لضمان دقة التحليل:</h3>
|
|
|
|
| 181 |
</div>
|
| 182 |
"""
|
| 183 |
|
| 184 |
+
custom_css = """
|
| 185 |
+
button, .btn, .gr-button {
|
| 186 |
+
background-color: #2e7d32 !important;
|
| 187 |
+
color: white !important;
|
| 188 |
+
font-weight: 600 !important;
|
| 189 |
+
border-radius: 8px !important;
|
| 190 |
+
}
|
| 191 |
+
"""
|
| 192 |
+
|
| 193 |
+
with gr.Blocks(title="تحليل المشية العصبية - v8.2 (واجهة خضراء)", css=custom_css) as demo:
|
| 194 |
gr.Markdown("<h2 style='direction:rtl;text-align:right'>🩺 نظام تحليل المشية العصبية – الإصدار 8.2</h2>")
|
| 195 |
gr.HTML(instructions)
|
| 196 |
with gr.Row():
|
| 197 |
with gr.Column(scale=1):
|
| 198 |
video_in = gr.File(label="📂 اختر فيديو المشي", file_types=[".mp4", ".avi", ".mov"], type="binary")
|
| 199 |
+
analyze_btn = gr.Button("🔍 بدء التحليل")
|
| 200 |
with gr.Column(scale=1):
|
| 201 |
gauge = gr.HTML("<div></div>")
|
| 202 |
out_html = gr.HTML("<i style='direction:rtl;text-align:right'>النتيجة ستظهر هنا بعد التحليل...</i>")
|
| 203 |
analyze_btn.click(fn=analyze_gait, inputs=[video_in], outputs=[out_html, gauge])
|
| 204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
if __name__ == "__main__":
|
| 206 |
demo.launch()
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
|
|
|
| 211 |
|
| 212 |
|