Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
model_path = "."
|
|
@@ -21,16 +22,17 @@ def apply_clinical_rules(text, predicted_label, confidence):
|
|
| 21 |
text = text.lower()
|
| 22 |
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
fluency_keywords = ['تأتأة', 'يعلق', 'يكرر', 'تمتمة', 'طويل', 'شد']
|
| 28 |
-
|
| 29 |
|
|
|
|
| 30 |
if any(k in text for k in ssd_keywords) and predicted_label != 'Speech Sound Disorder (مخارج الحروف)':
|
| 31 |
-
return 'Speech Sound Disorder (مخارج الحروف)', 0.85
|
| 32 |
|
| 33 |
|
|
|
|
| 34 |
if any(k in text for k in fluency_keywords) and predicted_label != 'Fluency Disorder (تأتأة)':
|
| 35 |
return 'Fluency Disorder (تأتأة)', 0.90
|
| 36 |
|
|
@@ -49,40 +51,42 @@ def predict_speech_issue(text):
|
|
| 49 |
|
| 50 |
ai_label = id2label[pred_id]
|
| 51 |
|
| 52 |
-
|
| 53 |
final_label, final_confidence = apply_clinical_rules(text, ai_label, confidence)
|
| 54 |
|
| 55 |
-
|
| 56 |
recommendations = {
|
| 57 |
'Speech Sound Disorder (مخارج الحروف)': "ينصح بتقييم مخارج الحروف وفحص أعضاء النطق (Oral Motor Exam).",
|
| 58 |
'Language Disorder (تأخر لغة)': "ينصح بعمل اختبار لغة شامل لتقييم اللغة الاستقبالية والتعبيرية.",
|
| 59 |
'Social Communication/ASD (تواصل واجتماعي)': "ينصح بمراجعة طبيب نمو وسلوك وعمل تقييم تواصل اجتماعي.",
|
| 60 |
'Fluency Disorder (تأتأة)': "ينصح بمراقبة بيئة الطفل وتقليل الضغوط التواصلية.",
|
| 61 |
'Motor Speech Disorder (اضطراب حركي)': "يحتاج تقييم دقيق لاحتمالية وجود Apraxia أو Dysarthria.",
|
| 62 |
-
'Other/Medical (أخرى/طبية)': "يف
|
| 63 |
}
|
| 64 |
|
| 65 |
advice = recommendations.get(final_label, "يرجى استشارة مختص.")
|
| 66 |
|
| 67 |
-
|
| 68 |
correction_note = ""
|
| 69 |
if final_label != ai_label:
|
| 70 |
-
correction_note = "<br><span style='font-size:0.8em; color:gray;'>(تم تعديل النتيجة بناءً على
|
| 71 |
|
| 72 |
return f"""
|
| 73 |
-
<div style="direction: rtl; text-align: right; padding:
|
| 74 |
-
<h2 style="color: #
|
| 75 |
-
<p><b>درجة ال
|
| 76 |
-
<
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
</div>
|
| 79 |
"""
|
| 80 |
|
| 81 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 82 |
-
gr.Markdown(" أداة الفرز الذكية لاضطرابات النطق - المراعية للهجات السعودية")
|
| 83 |
-
input_txt = gr.Textbox(label="وصف ا
|
| 84 |
-
btn = gr.Button("تحليل", variant="primary")
|
| 85 |
-
output = gr.HTML(label="ال
|
| 86 |
btn.click(fn=predict_speech_issue, inputs=input_txt, outputs=output)
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
|
| 7 |
model_path = "."
|
|
|
|
| 22 |
text = text.lower()
|
| 23 |
|
| 24 |
|
| 25 |
+
voice_keywords = ['مبحوح', 'بحّة', 'بحة', 'خشن', 'صوته رايح', 'مكتوم', 'انقطاع النفس']
|
| 26 |
+
if any(k in text for k in voice_keywords):
|
| 27 |
+
return 'Other/Medical (أخرى/طبية)', 0.95
|
| 28 |
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
ssd_keywords = ['حرف', 'ينطق', 'بدل', 'لثغة', 'الراء', 'السين', 'كلامه مو واضح', 'مخارج', 'ابدال', 'حذف', 'تشويه']
|
| 31 |
if any(k in text for k in ssd_keywords) and predicted_label != 'Speech Sound Disorder (مخارج الحروف)':
|
| 32 |
+
return 'Speech Sound Disorder (مخارج الحروف)', 0.85
|
| 33 |
|
| 34 |
|
| 35 |
+
fluency_keywords = ['تأتأة', 'يعلق', 'يكرر', 'تمتمة', 'طويل', 'شد في الكلام']
|
| 36 |
if any(k in text for k in fluency_keywords) and predicted_label != 'Fluency Disorder (تأتأة)':
|
| 37 |
return 'Fluency Disorder (تأتأة)', 0.90
|
| 38 |
|
|
|
|
| 51 |
|
| 52 |
ai_label = id2label[pred_id]
|
| 53 |
|
| 54 |
+
|
| 55 |
final_label, final_confidence = apply_clinical_rules(text, ai_label, confidence)
|
| 56 |
|
| 57 |
+
|
| 58 |
recommendations = {
|
| 59 |
'Speech Sound Disorder (مخارج الحروف)': "ينصح بتقييم مخارج الحروف وفحص أعضاء النطق (Oral Motor Exam).",
|
| 60 |
'Language Disorder (تأخر لغة)': "ينصح بعمل اختبار لغة شامل لتقييم اللغة الاستقبالية والتعبيرية.",
|
| 61 |
'Social Communication/ASD (تواصل واجتماعي)': "ينصح بمراجعة طبيب نمو وسلوك وعمل تقييم تواصل اجتماعي.",
|
| 62 |
'Fluency Disorder (تأتأة)': "ينصح بمراقبة بيئة الطفل وتقليل الضغوط التواصلية.",
|
| 63 |
'Motor Speech Disorder (اضطراب حركي)': "يحتاج تقييم دقيق لاحتمالية وجود Apraxia أو Dysarthria.",
|
| 64 |
+
'Other/Medical (أخرى/طبية)': " هذه الحالة قد تكون طبية (صوت/سمع). ينصح فوراً بمراجعة طبيب أنف وأذن وحنجرة (ENT) لفحص الحبال الصوتية أو السمع."
|
| 65 |
}
|
| 66 |
|
| 67 |
advice = recommendations.get(final_label, "يرجى استشارة مختص.")
|
| 68 |
|
|
|
|
| 69 |
correction_note = ""
|
| 70 |
if final_label != ai_label:
|
| 71 |
+
correction_note = "<br><span style='font-size:0.8em; color:gray;'>(تم تعديل النتيجة بناءً على الفحص السريري للنص)</span>"
|
| 72 |
|
| 73 |
return f"""
|
| 74 |
+
<div style="direction: rtl; text-align: right; padding: 20px; background-color: #fff; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
| 75 |
+
<h2 style="color: #2e86de; margin-bottom: 10px;">التصنيف المقترح: {final_label}</h2>
|
| 76 |
+
<p style="color: #555;"><b>درجة المطابقة:</b> {final_confidence:.1%} {correction_note}</p>
|
| 77 |
+
<div style="background-color: #ffeaa7; padding: 15px; border-radius: 8px; margin-top: 15px; border-right: 5px solid #fdcb6e;">
|
| 78 |
+
<p style="color: #d35400; font-weight: bold; margin: 0;"> التوصية المختصة:</p>
|
| 79 |
+
<p style="margin-top: 5px;">{advice}</p>
|
| 80 |
+
</div>
|
| 81 |
</div>
|
| 82 |
"""
|
| 83 |
|
| 84 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 85 |
+
gr.Markdown("<h1 style='text-align: center'>أداة الفرز الذكية لاضطرابات النطق - المراعية للهجات السعودية</h1>")
|
| 86 |
+
input_txt = gr.Textbox(label="وصف ا��حالة (بالعامية)", placeholder="مثال: ولدي صوته متغير ومبحوح.. أو بنتي تبدل الراء غين")
|
| 87 |
+
btn = gr.Button("تحليل الحالة", variant="primary")
|
| 88 |
+
output = gr.HTML(label="التقرير")
|
| 89 |
btn.click(fn=predict_speech_issue, inputs=input_txt, outputs=output)
|
| 90 |
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
demo.launch()
|