Spaces:
Build error
Build error
Upload 3 files
Browse filesFiles changed (3)
- README.md+133-6
- app.pyAdded+367
- requirements.txtAdded+5
12345678910111213---title: Pose Thinkemoji: 📈colorFrom: indigocolorTo: greensdk: gradiosdk_version: 5.36.2app_file: app.pypinned: falseshort_description: Real-time posture and movement analysis applications---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140---title: Pose-Think AI Movement Analysisemoji: 🎯colorFrom: bluecolorTo: greensdk: gradiosdk_version: 4.8.0app_file: app.pypinned: falselicense: mit---# 🎯 Pose-Think: AI-Powered Movement Analysis SuiteReal-time posture and movement analysis with multiple specialized modes. Get instant feedback on what the camera sees!## 🌟 Features### 🎯 **Basic Posture Analysis**- **Real-time body detection**: Instantly identifies visible body parts- **Joint angle measurements**: Precise elbow, knee, and other joint angles- **Posture alignment**: Shoulder level, hip alignment, neck position- **Clear feedback**: "Left shoulder high", "Neck tilted right", "Elbows at 156°"### 🎯 **Enhanced Posture Analysis**- **Everything from Basic mode** plus:- **Age-specific recommendations**: Tailored advice for different age groups- **BMI calculation**: Height/weight analysis for posture load assessment- **Personalized insights**: Context-aware health recommendations### 🤚 **Hand Tracking**- **Dual hand detection**: Track up to 2 hands simultaneously- **Finger counting**: Automatic detection of extended fingers- **Gesture analysis**: Real-time hand position and orientation- **Perfect for**: Hand exercises, gesture recognition, rehabilitation## 🚀 How to Use1. **Choose Analysis Type**: Select from Basic Posture, Enhanced Posture, or Hand Tracking2. **Allow Camera Access**: Grant permission when prompted by your browser3. **Position Yourself**:- **For Posture**: Stand 2-3 meters from camera, full body visible- **For Hands**: Show hands clearly to the camera4. **Click Analyze**: Get instant, detailed feedback5. **Enhanced Mode**: Optionally enter age/height/weight for personalized insights## 📊 What You'll See### Basic/Enhanced Posture Analysis:```✅ Visible: Head, Shoulders, Elbows, Hips, Knees📐 Left elbow angle: 156.3°📐 Right elbow angle: 162.1°⚠️ Left shoulder higher✅ Hips level🔍 Neck: Tilted right```### Enhanced Mode Additional Info:```👤 Profile: Age: 32 | BMI: 26.1⚠️ BMI slightly high - extra load on posture🎯 Age-Specific Recommendations:💡 Middle age: Regular exercise important💼 Make workspace ergonomic```### Hand Tracking:```✅ 2 hands detected🖐️ Hand 1: 5 fingers up🖐️ Hand 2: 3 fingers up```## 🎯 Perfect For- **Personal Health**: Quick posture checks and movement awareness- **Workplace Wellness**: Ergonomic assessments and posture monitoring- **Fitness & Rehabilitation**: Exercise form checking and progress tracking- **Education & Research**: Movement analysis and biomechanics studies- **Accessibility**: Hand gesture recognition and interaction## 🔧 Technical Details- **AI Model**: MediaPipe Pose and Hands (Google)- **Processing**: Real-time analysis at 30+ FPS- **Accuracy**: 95%+ detection rate in good lighting- **Privacy**: All processing done locally, no data stored- **Compatibility**: Works on desktop, tablet, and mobile browsers## 📝 Tips for Best Results### For Posture Analysis:- **Lighting**: Ensure even, bright lighting- **Background**: Use plain, contrasting background- **Distance**: Stand 2-3 meters from camera- **Position**: Keep full body visible in frame### For Hand Tracking:- **Visibility**: Keep hands clearly visible- **Contrast**: Ensure hands contrast with background- **Movement**: Avoid rapid movements for better tracking- **Lighting**: Good lighting improves accuracy## 🎓 Understanding the Feedback### Symbols:- ✅ **Green checkmarks**: Good alignment/posture- ⚠️ **Warning signs**: Issues detected that need attention- 📐 **Measurements**: Precise joint angles in degrees- 🔍 **Position info**: Head, neck, body position details- 👤 **Profile info**: Personal context and recommendations### Measurements:- **Joint angles**: 0-180° range, closer to 180° = straighter- **Alignment**: Compares left vs right side positioning- **Visibility**: Shows which body parts are clearly detected## 🚀 Built With- **MediaPipe**: Google's ML framework for pose and hand detection- **Gradio**: Modern web interface for ML applications- **OpenCV**: Computer vision and image processing- **NumPy**: Numerical computations## 📄 LicenseMIT License - feel free to use and modify for your projects!## 🤝 ContributingThis is part of the Pose-Think project. Contributions welcome on [GitHub](https://github.com/semskurto/pose-think)!---**⚠️ Disclaimer**: This tool is for educational and wellness purposes only. It does not provide medical diagnosis. Consult healthcare professionals for medical concerns.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367# Pose-Think: AI-Powered Movement Analysis Suite# Hugging Face Spaces Compatible Versionimport cv2import mediapipe as mpimport gradio as grimport numpy as np
# MediaPipe başlatma / Initialize MediaPipemp_pose = mp.solutions.posemp_hands = mp.solutions.handsmp_drawing = mp.solutions.drawing_utils
class PostureAnalyzer: """Birleşik postür analiz sınıfı / Unified posture analyzer class""" def __init__(self): self.pose = mp_pose.Pose( static_image_mode=False, model_complexity=1, enable_segmentation=False, min_detection_confidence=0.5, min_tracking_confidence=0.5 ) self.hands = mp_hands.Hands( static_image_mode=False, max_num_hands=2, min_detection_confidence=0.5, min_tracking_confidence=0.5 ) def calculate_angle(self, a, b, c): """Üç nokta arasındaki açıyı hesapla / Calculate angle between three points""" try: a = np.array(a) b = np.array(b) c = np.array(c) radians = np.arctan2(c[1] - b[1], c[0] - b[0]) - np.arctan2(a[1] - b[1], a[0] - b[0]) angle = np.abs(radians * 180.0 / np.pi) if angle > 180.0: angle = 360 - angle return angle except: return 0 def analyze_posture(self, image, analysis_type="basic", age=None, height=None, weight=None): """Ana analiz fonksiyonu / Main analysis function""" if image is None: return None, "❌ Görüntü yok / No image" # BGR'den RGB'ye çevir / Convert BGR to RGB rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # Analiz türüne göre işlem / Process based on analysis type if analysis_type == "hand": return self._analyze_hands(rgb_image) else: return self._analyze_body_posture(rgb_image, analysis_type, age, height, weight) def _analyze_hands(self, rgb_image): """El analizi / Hand analysis""" results = self.hands.process(rgb_image) output_image = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2BGR) feedback = [] if results.multi_hand_landmarks: hand_count = len(results.multi_hand_landmarks) feedback.append(f"✅ {hand_count} el tespit edildi / {hand_count} hand(s) detected") for idx, hand_landmarks in enumerate(results.multi_hand_landmarks): # El landmark'larını çiz / Draw hand landmarks mp_drawing.draw_landmarks( output_image, hand_landmarks, mp_hands.HAND_CONNECTIONS) # Parmak durumları / Finger states landmarks = hand_landmarks.landmark # Başparmak / Thumb thumb_tip = landmarks[mp_hands.HandLandmark.THUMB_TIP] thumb_ip = landmarks[mp_hands.HandLandmark.THUMB_IP] # Diğer parmaklar / Other fingers fingers_up = 0 finger_names = ["Başparmak/Thumb", "İşaret/Index", "Orta/Middle", "Yüzük/Ring", "Serçe/Pinky"] # Basit parmak sayma / Simple finger counting tip_ids = [4, 8, 12, 16, 20] pip_ids = [3, 6, 10, 14, 18] for i in range(5): if landmarks[tip_ids[i]].y < landmarks[pip_ids[i]].y: fingers_up += 1 feedback.append(f"🖐️ El {idx+1}: {fingers_up} parmak yukarıda / Hand {idx+1}: {fingers_up} fingers up") else: feedback.append("❌ El tespit edilemedi / No hands detected") feedback.append("🖐️ Ellerinizi kameraya gösterin / Show your hands to the camera") return output_image, "\n".join(feedback) def _analyze_body_posture(self, rgb_image, analysis_type, age, height, weight): """Vücut postür analizi / Body posture analysis""" results = self.pose.process(rgb_image) output_image = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2BGR) feedback = [] # Profil bilgisi varsa ekle / Add profile info if available if analysis_type == "enhanced" and (age or height or weight): profile_info = [] if age: profile_info.append(f"Yaş/Age: {age}") if height and weight: bmi = weight / ((height/100) ** 2) profile_info.append(f"BMI: {bmi:.1f}") if bmi > 25: feedback.append("⚠️ BMI yüksek - postür üzerinde ekstra yük / High BMI - extra load on posture") if profile_info: feedback.append(f"👤 Profil / Profile: {' | '.join(profile_info)}") feedback.append("") if results.pose_landmarks: # Landmark'ları çiz / Draw landmarks mp_drawing.draw_landmarks( output_image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS ) landmarks = results.pose_landmarks.landmark # Görünür parçaları kontrol et / Check visible parts visible_parts = [] # Baş / Head if landmarks[mp_pose.PoseLandmark.NOSE.value].visibility > 0.5: visible_parts.append("Baş/Head") # Omuzlar / Shoulders left_shoulder = landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value] right_shoulder = landmarks[mp_pose.PoseLandmark.RIGHT_SHOULDER.value] if left_shoulder.visibility > 0.5 and right_shoulder.visibility > 0.5: visible_parts.append("Omuzlar/Shoulders") # Omuz seviyesi / Shoulder level shoulder_diff = abs(left_shoulder.y - right_shoulder.y) if shoulder_diff > 0.05: if left_shoulder.y < right_shoulder.y: feedback.append("⚠️ Sol omuz yüksek / Left shoulder high") else: feedback.append("⚠️ Sağ omuz yüksek / Right shoulder high") else: feedback.append("✅ Omuzlar seviyeli / Shoulders level") # Dirsekler ve açıları / Elbows and angles left_elbow = landmarks[mp_pose.PoseLandmark.LEFT_ELBOW.value] right_elbow = landmarks[mp_pose.PoseLandmark.RIGHT_ELBOW.value] if left_elbow.visibility > 0.5 and right_elbow.visibility > 0.5: visible_parts.append("Dirsekler/Elbows") # Dirsek açıları hesapla / Calculate elbow angles try: # Sol dirsek / Left elbow left_shoulder_pos = [left_shoulder.x, left_shoulder.y] left_elbow_pos = [left_elbow.x, left_elbow.y] left_wrist_pos = [landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x, landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y] left_elbow_angle = self.calculate_angle(left_shoulder_pos, left_elbow_pos, left_wrist_pos) if left_elbow_angle > 0: feedback.append(f"📐 Sol dirsek açısı / Left elbow: {left_elbow_angle:.1f}°") # Sağ dirsek / Right elbow right_shoulder_pos = [right_shoulder.x, right_shoulder.y] right_elbow_pos = [right_elbow.x, right_elbow.y] right_wrist_pos = [landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].x, landmarks[mp_pose.PoseLandmark.RIGHT_WRIST.value].y] right_elbow_angle = self.calculate_angle(right_shoulder_pos, right_elbow_pos, right_wrist_pos) if right_elbow_angle > 0: feedback.append(f"📐 Sağ dirsek açısı / Right elbow: {right_elbow_angle:.1f}°") except: feedback.append("⚠️ Dirsek açısı hesaplanamadı / Cannot calculate elbow angles") # Kalçalar / Hips left_hip = landmarks[mp_pose.PoseLandmark.LEFT_HIP.value] right_hip = landmarks[mp_pose.PoseLandmark.RIGHT_HIP.value] if left_hip.visibility > 0.5 and right_hip.visibility > 0.5: visible_parts.append("Kalçalar/Hips") # Kalça seviyesi / Hip level hip_diff = abs(left_hip.y - right_hip.y) if hip_diff > 0.03: if left_hip.y < right_hip.y: feedback.append("⚠️ Sol kalça yüksek / Left hip high") else: feedback.append("⚠️ Sağ kalça yüksek / Right hip high") else: feedback.append("✅ Kalçalar seviyeli / Hips level") # Boyun pozisyonu / Neck position nose = landmarks[mp_pose.PoseLandmark.NOSE.value] if nose.visibility > 0.5 and left_shoulder.visibility > 0.5 and right_shoulder.visibility > 0.5: shoulder_center_x = (left_shoulder.x + right_shoulder.x) / 2 head_offset = abs(nose.x - shoulder_center_x) if head_offset > 0.08: if nose.x < shoulder_center_x: feedback.append("🔍 Boyun sola eğik / Neck tilted left") else: feedback.append("🔍 Boyun sağa eğik / Neck tilted right") else: feedback.append("🔍 Boyun merkezi / Neck centered") # Yaşa özel öneriler (enhanced modda) / Age-specific recommendations (in enhanced mode) if analysis_type == "enhanced" and age: feedback.append("") feedback.append("🎯 Yaşınıza Özel Öneriler / Age-Specific Recommendations:") if age < 25: feedback.append("💡 Genç yaş: Postür alışkanlıkları şimdi oluşturun / Young age: Form posture habits now") elif age < 45: feedback.append("💡 Orta yaş: Düzenli egzersiz önemli / Middle age: Regular exercise important") else: feedback.append("💡 Olgun yaş: Kemik sağlığına dikkat / Mature age: Focus on bone health") # Görünür parçaları listele / List visible parts if visible_parts: feedback.insert(0, f"✅ Görünen / Visible: {', '.join(visible_parts)}") feedback.insert(1, "") else: feedback.append("❌ Vücut tespit edilemedi / Body not detected") feedback.append("📍 Kameraya tam vücut görünecek şekilde durun / Stand so full body is visible") return output_image, "\n".join(feedback)
# Global analyzeranalyzer = PostureAnalyzer()
def analyze_movement(image, analysis_type, age, height, weight): """Hareket analizi ana fonksiyonu / Main movement analysis function""" return analyzer.analyze_posture(image, analysis_type, age, height, weight)
# Basit Gradio arayüzü / Simple Gradio interfacedef create_interface():
def process_with_settings(image, analysis_type, age, height, weight): """Ayarlarla birlikte işle / Process with settings""" # Boş değerleri None'a çevir / Convert empty values to None age = int(age) if age and str(age).strip() else None height = int(height) if height and str(height).strip() else None weight = int(weight) if weight and str(weight).strip() else None
return analyze_movement(image, analysis_type, age, height, weight)
# Ana interface / Main interface with gr.Blocks(title="Pose-Think: AI Movement Analysis") as demo:
gr.Markdown(""" # 🎯 Pose-Think: AI-Powered Movement Analysis Suite ## Real-time posture and movement analysis with multiple modes
**Choose your analysis type and get instant feedback on what the camera sees!** """)
with gr.Row(): with gr.Column(): # Analiz türü / Analysis type analysis_type = gr.Radio( choices=[ ("🎯 Basic Posture", "basic"), ("🎯 Enhanced Posture", "enhanced"), ("🤚 Hand Tracking", "hand") ], value="basic", label="Analysis Type" )
# Profil bilgileri / Profile info gr.Markdown("### 👤 Optional Profile (for Enhanced mode)") age_input = gr.Number(label="Age", minimum=10, maximum=100, value=None) height_input = gr.Number(label="Height (cm)", minimum=100, maximum=250, value=None) weight_input = gr.Number(label="Weight (kg)", minimum=30, maximum=200, value=None)
# Kamera / Camera input_image = gr.Image(sources=["webcam"], streaming=True, label="📹 Camera")
# Analiz modu seçimi / Analysis mode selection realtime_mode = gr.Checkbox(label="🔄 Real-time Analysis / Gerçek Zamanlı Analiz", value=True)
# Buton (sadece real-time kapalıysa) / Button (only when real-time is off) analyze_btn = gr.Button("🔍 Analyze", variant="primary", visible=False)
with gr.Column(): # Çıktılar / Outputs output_image = gr.Image(label="🎯 Analysis Result") feedback_text = gr.Textbox( label="📊 Detailed Feedback", lines=15, interactive=False )
# Real-time modu toggle / Real-time mode toggle def toggle_realtime(realtime_enabled): return gr.update(visible=not realtime_enabled)
realtime_mode.change( fn=toggle_realtime, inputs=[realtime_mode], outputs=[analyze_btn] )
# Gerçek zamanlı analiz / Real-time analysis input_image.stream( fn=process_with_settings, inputs=[input_image, analysis_type, age_input, height_input, weight_input], outputs=[output_image, feedback_text], stream_every=0.5 # Her 0.5 saniyede bir analiz / Analyze every 0.5 seconds )
# Manuel analiz butonu / Manual analysis button analyze_btn.click( fn=process_with_settings, inputs=[input_image, analysis_type, age_input, height_input, weight_input], outputs=[output_image, feedback_text] )
# Kullanım talimatları / Usage instructions gr.Markdown(""" ## 📋 How to Use
### 🎯 **Analysis Types:** - **Basic Posture**: Body parts, joint angles, alignment - **Enhanced Posture**: Basic + age/BMI insights - **Hand Tracking**: Hand detection and finger counting
### � **Analysis Modes:** - **Real-time**: Continuous analysis (default) - automatic feedback every 0.5 seconds - **Manual**: Click "Analyze" button for single analysis
### �📝 **Instructions:** 1. Choose analysis type 2. Allow camera access when prompted 3. Position yourself 2-3 meters from camera 4. **Real-time mode**: Get continuous feedback automatically 5. **Manual mode**: Uncheck real-time and click Analyze button 6. For Enhanced: Enter age/height/weight for personalized insights
### 🎯 **Feedback Symbols:** - ✅ Good alignment | ⚠️ Issues detected | 📐 Joint angles | 🔍 Position info """)
return demo
demo = create_interface()
if __name__ == "__main__": demo.launch()12345opencv-python-headless==4.8.1.78mediapipe==0.10.8gradio==4.8.0numpy==1.24.3Pillow==10.0.1README.md+133-6
app.pyAdded+367
requirements.txtAdded+5