Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- Dockerfile +13 -0
- README.md +10 -10
- main.py +76 -0
- requirements.txt +6 -0
Dockerfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
+
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
EXPOSE 7860
|
| 12 |
+
|
| 13 |
+
CMD ["python", "main.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
---
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Rafiq AI
|
| 3 |
+
emoji: 🤖
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Rafiq AI Recommendation System
|
main.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import uvicorn
|
| 5 |
+
|
| 6 |
+
app = FastAPI(
|
| 7 |
+
title="Rafiq AI Recommendation API",
|
| 8 |
+
description="AI recommendation system for autism therapy plans",
|
| 9 |
+
version="1.0"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# ================= AI MODEL =================
|
| 13 |
+
|
| 14 |
+
generator = pipeline(
|
| 15 |
+
"text-generation",
|
| 16 |
+
model="distilgpt2"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# ================= Request Model =================
|
| 20 |
+
|
| 21 |
+
class AssessmentData(BaseModel):
|
| 22 |
+
cars_score: float
|
| 23 |
+
vineland_avg: float
|
| 24 |
+
|
| 25 |
+
# ================= AI Recommendation =================
|
| 26 |
+
|
| 27 |
+
@app.post("/recommend")
|
| 28 |
+
def recommend(data: AssessmentData):
|
| 29 |
+
|
| 30 |
+
# حساب الدرجة المركبة
|
| 31 |
+
composite_score = (
|
| 32 |
+
(data.cars_score * 0.5)
|
| 33 |
+
+ ((2 - data.vineland_avg) * 25 * 0.3)
|
| 34 |
+
+ 20
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Prompt للـ AI
|
| 38 |
+
prompt = f"""
|
| 39 |
+
طفل توحد لديه:
|
| 40 |
+
CARS score = {data.cars_score}
|
| 41 |
+
Vineland average = {data.vineland_avg}
|
| 42 |
+
Composite score = {composite_score}
|
| 43 |
+
|
| 44 |
+
اعطيني:
|
| 45 |
+
- مستوى الحالة
|
| 46 |
+
- المرحلة المناسبة
|
| 47 |
+
- السلوكيات المهمة
|
| 48 |
+
- عدد الجلسات
|
| 49 |
+
- نصيحة علاجية قصيرة
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
result = generator(
|
| 53 |
+
prompt,
|
| 54 |
+
max_length=200,
|
| 55 |
+
do_sample=True
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
ai_text = result[0]["generated_text"]
|
| 59 |
+
|
| 60 |
+
return {
|
| 61 |
+
"composite_score": round(composite_score, 2),
|
| 62 |
+
"recommendation": ai_text
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
# ================= Root =================
|
| 66 |
+
|
| 67 |
+
@app.get("/")
|
| 68 |
+
def home():
|
| 69 |
+
return {
|
| 70 |
+
"message": "Rafiq AI API is running"
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
# ================= Run =================
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
transformers
|
| 4 |
+
torch
|
| 5 |
+
accelerate
|
| 6 |
+
sentencepiece
|