File size: 2,747 Bytes
94f22cd
8ce1e4b
 
 
 
94f22cd
 
 
 
 
 
 
8ce1e4b
94f22cd
8ce1e4b
94f22cd
8ce1e4b
94f22cd
8ce1e4b
 
 
fc5eb9b
8ce1e4b
fc5eb9b
8ce1e4b
 
 
 
 
 
 
 
fc5eb9b
4747664
fc5eb9b
8ce1e4b
 
 
 
 
 
 
 
 
fc5eb9b
8ce1e4b
fc5eb9b
8ce1e4b
 
 
 
 
 
fc5eb9b
8ce1e4b
 
 
fc5eb9b
 
 
8ce1e4b
 
 
 
 
 
 
 
fc5eb9b
8ce1e4b
 
 
 
fc5eb9b
 
 
8ce1e4b
fc5eb9b
8ce1e4b
 
fc5eb9b
4747664
 
8ce1e4b
fc5eb9b
8ce1e4b
 
fc5eb9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
title: StrokePainSideDetector
emoji: 🧠
colorFrom: red
colorTo: blue
sdk: streamlit
sdk_version: 1.44.1
app_file: app.py
pinned: false
license: mit
---

# 🧠 Stroke Patient Pain Intensity Detector

This app predicts the **pain intensity (PSPI score)** of stroke patients based on facial expressions using deep learning. It also detects the **affected side** of the face and uses the **unaffected half** for analysis.

## πŸš€ What This App Does

1. 🧠 **Detects affected side** of the face using a Keras CNN model.
2. 🎯 **Crops the unaffected side** of the face using OpenCV + Haar cascades.
3. πŸ“ˆ **Predicts pain score (PSPI)** using a PyTorch ResNet model.

If the face is tilted, the app will automatically rotate it for correct alignment before prediction.

---

## πŸ–ΌοΈ Input

Upload a **full-face photo** of a stroke patient. The app:
- Detects the face
- Splits the face in half (face point of view)
- Uses the expressive side for pain prediction

---

## πŸ“Š Output

- **Affected Side** (face point of view)
- **Unaffected Side**
- **Predicted PSPI Score**: A number between 0 and 6
- **Raw pain model output**
- **Raw stroke model output** (value closer to 0 β†’ left side affected; closer to 1 β†’ right side affected)

---

## πŸ“š PSPI Score Scale

| Score | Pain Level        |
|-------|-------------------|
| 0     | No pain           |
| 1–2   | Mild pain         |
| 3–4   | Moderate pain     |
| 5–6   | Severe pain       |

The PSPI (Prkachin and Solomon Pain Intensity) score is based on facial action units like eye tightening, brow lowering, and cheek raising.

---

## πŸ’Ύ Models Used

| Model                     | Task                            | Format         | Link                                                                 |
|--------------------------|----------------------------------|----------------|----------------------------------------------------------------------|
| `cnn_stroke_model.keras` | Detect affected facial side      | TensorFlow     | [Download](https://huggingface.co/AdhamQQ/cnn_stroke_model/resolve/main/cnn_stroke_model.keras) |
| `pain_model.pth`         | Predict PSPI pain intensity      | PyTorch        | [Download](https://huggingface.co/AdhamQQ/cnn_stroke_model/resolve/main/pain_model.pth)         |

---

## πŸ› οΈ Technologies

- **Streamlit** for the web interface
- **OpenCV** for face detection
- **TensorFlow/Keras** for stroke side classification
- **PyTorch** for PSPI pain intensity prediction

---

## 🀝 Credits

Developed by [Your Name or Team Name]  
With support from Hugging Face Spaces

---

## πŸ”— Live App

Launch it on Hugging Face Spaces:  
[πŸ‘‰ Try It Now](https://huggingface.co/spaces/YourUsername/StrokePainSideDetector)