Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,7 +40,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:
|
|
@@ -128,7 +127,7 @@ def analyze_gait(video_file):
|
|
| 128 |
score = min(score, 10)
|
| 129 |
norm_score = score / 10.0
|
| 130 |
|
| 131 |
-
#
|
| 132 |
if avg_Lc < avg_Rc - 2 and avg_La < avg_Ra:
|
| 133 |
side = "الجهة اليسرى"
|
| 134 |
elif avg_Rc < avg_Lc - 2 and avg_Ra < avg_La:
|
|
@@ -136,7 +135,7 @@ def analyze_gait(video_file):
|
|
| 136 |
else:
|
| 137 |
side = "غير محددة بوضوح"
|
| 138 |
|
| 139 |
-
#
|
| 140 |
if red_flags >= 3 and base_ratio > 0.25:
|
| 141 |
condition = "قدم شاركوت (Charcot Foot)"
|
| 142 |
elif min(avg_Lc, avg_Rc) < 4 or low_ratio_L > 0.4 or low_ratio_R > 0.4:
|
|
@@ -146,13 +145,28 @@ def analyze_gait(video_file):
|
|
| 146 |
else:
|
| 147 |
condition = "مشية طبيعية"
|
| 148 |
|
| 149 |
-
# مستوى الخطورة
|
| 150 |
if red_flags >= 2 or norm_score >= 0.7:
|
| 151 |
level, color, desc = "🔴 عالية الخطورة", "#c62828", "تم رصد مؤشرات متعددة لخلل واضح في المشية."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
elif norm_score >= 0.45:
|
| 153 |
level, color, desc = "🟡 متوسطة الخطورة", "#fbc02d", "مؤشرات تستدعي متابعة طبية دقيقة."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
else:
|
| 155 |
level, color, desc = "🟢 منخفضة الخطورة", "#2e7d32", "المشية ضمن النطاق السليم."
|
|
|
|
| 156 |
|
| 157 |
html = f"""
|
| 158 |
<div style='direction:rtl;text-align:right;color:{color};font-weight:700;font-size:18px'>{level}</div>
|
|
@@ -160,6 +174,7 @@ def analyze_gait(video_file):
|
|
| 160 |
<div style='direction:rtl;text-align:right'>🩺 الحالة المحتملة: <b>{condition}</b></div>
|
| 161 |
<div style='direction:rtl;text-align:right'>📊 درجة الخطورة: <b>{score:.1f}/10</b></div>
|
| 162 |
<div style='direction:rtl;text-align:right'>{desc}</div>
|
|
|
|
| 163 |
<div style='font-size:13px;color:#555;margin-top:8px;direction:rtl;text-align:right'>
|
| 164 |
⚠️ التحليل يعتمد على مؤشرات متعددة ولا يُغني عن الفحص الطبي.</div>
|
| 165 |
"""
|
|
|
|
| 40 |
if video_file is None:
|
| 41 |
return "<div style='direction:rtl;text-align:right'>❌ يرجى رفع فيديو أولًا.</div>", "<div></div>"
|
| 42 |
|
|
|
|
| 43 |
if hasattr(video_file, "name"):
|
| 44 |
video_path = video_file.name
|
| 45 |
else:
|
|
|
|
| 127 |
score = min(score, 10)
|
| 128 |
norm_score = score / 10.0
|
| 129 |
|
| 130 |
+
# الجهة المتضررة
|
| 131 |
if avg_Lc < avg_Rc - 2 and avg_La < avg_Ra:
|
| 132 |
side = "الجهة اليسرى"
|
| 133 |
elif avg_Rc < avg_Lc - 2 and avg_Ra < avg_La:
|
|
|
|
| 135 |
else:
|
| 136 |
side = "غير محددة بوضوح"
|
| 137 |
|
| 138 |
+
# الحالة المحتملة
|
| 139 |
if red_flags >= 3 and base_ratio > 0.25:
|
| 140 |
condition = "قدم شاركوت (Charcot Foot)"
|
| 141 |
elif min(avg_Lc, avg_Rc) < 4 or low_ratio_L > 0.4 or low_ratio_R > 0.4:
|
|
|
|
| 145 |
else:
|
| 146 |
condition = "مشية طبيعية"
|
| 147 |
|
| 148 |
+
# مستوى الخطورة + زر الحجز عند الحاجة
|
| 149 |
if red_flags >= 2 or norm_score >= 0.7:
|
| 150 |
level, color, desc = "🔴 عالية الخطورة", "#c62828", "تم رصد مؤشرات متعددة لخلل واضح في المشية."
|
| 151 |
+
booking = """
|
| 152 |
+
<div style='margin-top:10px;direction:rtl;text-align:right'>
|
| 153 |
+
<a href="https://example.com/book" target="_blank"
|
| 154 |
+
style="background:#2e7d32;color:#fff;padding:10px 16px;border-radius:8px;text-decoration:none;font-weight:600;">
|
| 155 |
+
احجز موعد مباشر (حضوري أو أونلاين)
|
| 156 |
+
</a>
|
| 157 |
+
</div>"""
|
| 158 |
elif norm_score >= 0.45:
|
| 159 |
level, color, desc = "🟡 متوسطة الخطورة", "#fbc02d", "مؤشرات تستدعي متابعة طبية دقيقة."
|
| 160 |
+
booking = """
|
| 161 |
+
<div style='margin-top:10px;direction:rtl;text-align:right'>
|
| 162 |
+
<a href="https://example.com/book" target="_blank"
|
| 163 |
+
style="background:#2e7d32;color:#fff;padding:10px 16px;border-radius:8px;text-decoration:none;font-weight:600;">
|
| 164 |
+
احجز استشارة طبية
|
| 165 |
+
</a>
|
| 166 |
+
</div>"""
|
| 167 |
else:
|
| 168 |
level, color, desc = "🟢 منخفضة الخطورة", "#2e7d32", "المشية ضمن النطاق السليم."
|
| 169 |
+
booking = ""
|
| 170 |
|
| 171 |
html = f"""
|
| 172 |
<div style='direction:rtl;text-align:right;color:{color};font-weight:700;font-size:18px'>{level}</div>
|
|
|
|
| 174 |
<div style='direction:rtl;text-align:right'>🩺 الحالة المحتملة: <b>{condition}</b></div>
|
| 175 |
<div style='direction:rtl;text-align:right'>📊 درجة الخطورة: <b>{score:.1f}/10</b></div>
|
| 176 |
<div style='direction:rtl;text-align:right'>{desc}</div>
|
| 177 |
+
{booking}
|
| 178 |
<div style='font-size:13px;color:#555;margin-top:8px;direction:rtl;text-align:right'>
|
| 179 |
⚠️ التحليل يعتمد على مؤشرات متعددة ولا يُغني عن الفحص الطبي.</div>
|
| 180 |
"""
|