Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title: Rafiq AI
|
| 3 |
emoji: 🤖
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Rafiq AI Recommendation
|
| 3 |
emoji: 🤖
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
main.py
CHANGED
|
@@ -3,74 +3,195 @@ from pydantic import BaseModel
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import uvicorn
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
app = FastAPI(
|
| 7 |
-
title="Rafiq AI Recommendation
|
| 8 |
-
description="AI recommendation system for autism
|
| 9 |
version="1.0"
|
| 10 |
)
|
| 11 |
|
| 12 |
-
# =================
|
|
|
|
|
|
|
| 13 |
|
| 14 |
generator = pipeline(
|
| 15 |
"text-generation",
|
| 16 |
model="distilgpt2"
|
| 17 |
)
|
| 18 |
|
| 19 |
-
# =================
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
class
|
| 22 |
cars_score: float
|
| 23 |
vineland_avg: float
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
@app.post("/recommend")
|
| 28 |
-
def recommend(data:
|
| 29 |
|
|
|
|
| 30 |
# حساب الدرجة المركبة
|
|
|
|
|
|
|
| 31 |
composite_score = (
|
| 32 |
(data.cars_score * 0.5)
|
| 33 |
+ ((2 - data.vineland_avg) * 25 * 0.3)
|
| 34 |
-
+
|
| 35 |
)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Prompt للـ AI
|
|
|
|
|
|
|
| 38 |
prompt = f"""
|
| 39 |
طفل توحد لديه:
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
"""
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
result = generator(
|
| 53 |
prompt,
|
| 54 |
-
max_length=
|
| 55 |
-
do_sample=True
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
ai_text = result[0]["generated_text"]
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
"composite_score": round(composite_score, 2),
|
| 62 |
-
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
-
# =================
|
|
|
|
|
|
|
| 66 |
|
| 67 |
@app.get("/")
|
| 68 |
def home():
|
| 69 |
return {
|
| 70 |
-
"message": "Rafiq AI
|
| 71 |
}
|
| 72 |
|
| 73 |
-
# =================
|
|
|
|
|
|
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
| 76 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import uvicorn
|
| 5 |
|
| 6 |
+
# =========================
|
| 7 |
+
# إنشاء التطبيق
|
| 8 |
+
# =========================
|
| 9 |
+
|
| 10 |
app = FastAPI(
|
| 11 |
+
title="Rafiq AI Recommendation System",
|
| 12 |
+
description="AI therapy recommendation system for autism children",
|
| 13 |
version="1.0"
|
| 14 |
)
|
| 15 |
|
| 16 |
+
# =========================
|
| 17 |
+
# تحميل موديل الذكاء الاصطناعي
|
| 18 |
+
# =========================
|
| 19 |
|
| 20 |
generator = pipeline(
|
| 21 |
"text-generation",
|
| 22 |
model="distilgpt2"
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# =========================
|
| 26 |
+
# Request Model
|
| 27 |
+
# =========================
|
| 28 |
|
| 29 |
+
class ChildAssessment(BaseModel):
|
| 30 |
cars_score: float
|
| 31 |
vineland_avg: float
|
| 32 |
+
behavior_score: float
|
| 33 |
+
|
| 34 |
+
# =========================
|
| 35 |
+
# تحديد المرحلة
|
| 36 |
+
# =========================
|
| 37 |
+
|
| 38 |
+
def determine_stage(composite_score):
|
| 39 |
+
|
| 40 |
+
if composite_score >= 48:
|
| 41 |
+
return {
|
| 42 |
+
"stage": 1,
|
| 43 |
+
"name": "التعرف الاجتماعي",
|
| 44 |
+
"activities": [
|
| 45 |
+
"التعرف على الأم والأب",
|
| 46 |
+
"التعرف على الإخوات",
|
| 47 |
+
"التعرف على الحيوانات الأساسية",
|
| 48 |
+
"التعرف على الخضروات والفواكه",
|
| 49 |
+
"التعرف على المنزل والمدرسة"
|
| 50 |
+
],
|
| 51 |
+
"sessions": 5,
|
| 52 |
+
"repetitions": 10,
|
| 53 |
+
"break_time": "يوم"
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
elif composite_score >= 32:
|
| 57 |
+
return {
|
| 58 |
+
"stage": 2,
|
| 59 |
+
"name": "التفاعل الاجتماعي",
|
| 60 |
+
"activities": [
|
| 61 |
+
"فهم نعم ولا",
|
| 62 |
+
"مرحبا وباي",
|
| 63 |
+
"تبادل الأدوار",
|
| 64 |
+
"اللعب الجماعي",
|
| 65 |
+
"انتظار الدور"
|
| 66 |
+
],
|
| 67 |
+
"sessions": 4,
|
| 68 |
+
"repetitions": 8,
|
| 69 |
+
"break_time": "يومين"
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
else:
|
| 73 |
+
return {
|
| 74 |
+
"stage": 3,
|
| 75 |
+
"name": "التواصل الاجتماعي",
|
| 76 |
+
"activities": [
|
| 77 |
+
"بدء الحوار",
|
| 78 |
+
"الإجابة على الأسئلة",
|
| 79 |
+
"التعبير عن الاحتياجات",
|
| 80 |
+
"بدء اللعب مع الآخرين",
|
| 81 |
+
"المحادثات البسيطة"
|
| 82 |
+
],
|
| 83 |
+
"sessions": 3,
|
| 84 |
+
"repetitions": 5,
|
| 85 |
+
"break_time": "3 أيام"
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
# =========================
|
| 89 |
+
# AI Recommendation Endpoint
|
| 90 |
+
# =========================
|
| 91 |
|
| 92 |
@app.post("/recommend")
|
| 93 |
+
def recommend(data: ChildAssessment):
|
| 94 |
|
| 95 |
+
# =====================
|
| 96 |
# حساب الدرجة المركبة
|
| 97 |
+
# =====================
|
| 98 |
+
|
| 99 |
composite_score = (
|
| 100 |
(data.cars_score * 0.5)
|
| 101 |
+ ((2 - data.vineland_avg) * 25 * 0.3)
|
| 102 |
+
+ (data.behavior_score * 0.2)
|
| 103 |
)
|
| 104 |
|
| 105 |
+
# =====================
|
| 106 |
+
# تحديد شدة الحالة
|
| 107 |
+
# =====================
|
| 108 |
+
|
| 109 |
+
if composite_score >= 48:
|
| 110 |
+
severity = "شديد"
|
| 111 |
+
elif composite_score >= 32:
|
| 112 |
+
severity = "متوسط"
|
| 113 |
+
else:
|
| 114 |
+
severity = "خفيف"
|
| 115 |
+
|
| 116 |
+
# =====================
|
| 117 |
+
# تحديد المرحلة
|
| 118 |
+
# =====================
|
| 119 |
+
|
| 120 |
+
stage_info = determine_stage(composite_score)
|
| 121 |
+
|
| 122 |
+
# =====================
|
| 123 |
# Prompt للـ AI
|
| 124 |
+
# =====================
|
| 125 |
+
|
| 126 |
prompt = f"""
|
| 127 |
طفل توحد لديه:
|
| 128 |
+
|
| 129 |
+
CARS Score = {data.cars_score}
|
| 130 |
+
Vineland Average = {data.vineland_avg}
|
| 131 |
+
Behavior Score = {data.behavior_score}
|
| 132 |
+
|
| 133 |
+
شدة الحالة: {severity}
|
| 134 |
+
|
| 135 |
+
المرحلة الحالية:
|
| 136 |
+
{stage_info['name']}
|
| 137 |
+
|
| 138 |
+
الأنشطة:
|
| 139 |
+
{', '.join(stage_info['activities'])}
|
| 140 |
+
|
| 141 |
+
اكتب نصيحة علاجية قصيرة ومفيدة للأهل.
|
| 142 |
"""
|
| 143 |
|
| 144 |
+
# =====================
|
| 145 |
+
# توليد النص
|
| 146 |
+
# =====================
|
| 147 |
+
|
| 148 |
result = generator(
|
| 149 |
prompt,
|
| 150 |
+
max_length=120,
|
| 151 |
+
do_sample=True,
|
| 152 |
+
temperature=0.7
|
| 153 |
)
|
| 154 |
|
| 155 |
ai_text = result[0]["generated_text"]
|
| 156 |
|
| 157 |
+
# =====================
|
| 158 |
+
# Response
|
| 159 |
+
# =====================
|
| 160 |
+
|
| 161 |
return {
|
| 162 |
+
|
| 163 |
+
"severity": severity,
|
| 164 |
+
|
| 165 |
+
"recommended_stage": stage_info["stage"],
|
| 166 |
+
|
| 167 |
+
"stage_name": stage_info["name"],
|
| 168 |
+
|
| 169 |
+
"activities": stage_info["activities"],
|
| 170 |
+
|
| 171 |
+
"sessions_per_week": stage_info["sessions"],
|
| 172 |
+
|
| 173 |
+
"repetitions_per_activity": stage_info["repetitions"],
|
| 174 |
+
|
| 175 |
+
"break_between_sessions": stage_info["break_time"],
|
| 176 |
+
|
| 177 |
"composite_score": round(composite_score, 2),
|
| 178 |
+
|
| 179 |
+
"ai_recommendation": ai_text
|
| 180 |
}
|
| 181 |
|
| 182 |
+
# =========================
|
| 183 |
+
# Home Endpoint
|
| 184 |
+
# =========================
|
| 185 |
|
| 186 |
@app.get("/")
|
| 187 |
def home():
|
| 188 |
return {
|
| 189 |
+
"message": "Rafiq AI Recommendation System Running"
|
| 190 |
}
|
| 191 |
|
| 192 |
+
# =========================
|
| 193 |
+
# تشغيل السيرفر
|
| 194 |
+
# =========================
|
| 195 |
|
| 196 |
if __name__ == "__main__":
|
| 197 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|