--- 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)