Spaces:
Sleeping
Sleeping
prabhjkaur
commited on
Commit
Β·
fa36863
1
Parent(s):
d8eceeb
Add Hugging face space configuration
Browse files
README.md
CHANGED
|
@@ -1,360 +1,15 @@
|
|
| 1 |
-
# AI Interview System - Modular Architecture
|
| 2 |
-
|
| 3 |
-
## π Project Structure
|
| 4 |
-
|
| 5 |
-
```
|
| 6 |
-
ai_interview_system/
|
| 7 |
-
β
|
| 8 |
-
βββ main_app.py # Main integration file (run this)
|
| 9 |
-
βββ recording_system.py # Module 1: Recording & Violation Detection
|
| 10 |
-
βββ analysis_system.py # Module 2: Multi-Modal Analysis
|
| 11 |
-
βββ scoring_dashboard.py # Module 3: Scoring & Dashboard
|
| 12 |
-
βββ README.md # This file
|
| 13 |
-
```
|
| 14 |
-
|
| 15 |
-
## π― Module Overview
|
| 16 |
-
|
| 17 |
-
### **Module 1: `recording_system.py`**
|
| 18 |
-
**Real-Time Interview Recording and Violation Detection System**
|
| 19 |
-
|
| 20 |
-
**Responsibilities:**
|
| 21 |
-
- Video and audio recording
|
| 22 |
-
- Real-time violation detection (multiple people, looking away, no face, cheating items)
|
| 23 |
-
- Eye contact tracking
|
| 24 |
-
- Blink detection
|
| 25 |
-
- Head pose estimation
|
| 26 |
-
- Lighting analysis
|
| 27 |
-
- Audio transcription
|
| 28 |
-
|
| 29 |
-
**Key Class:** `RecordingSystem`
|
| 30 |
-
|
| 31 |
-
**Main Method:** `record_interview(question_data, duration, ui_callbacks)`
|
| 32 |
-
|
| 33 |
-
---
|
| 34 |
-
|
| 35 |
-
### **Module 2: `analysis_system.py`**
|
| 36 |
-
**Multi-Modal Analysis System**
|
| 37 |
-
|
| 38 |
-
**Responsibilities:**
|
| 39 |
-
- Facial emotion analysis (DeepFace)
|
| 40 |
-
- Audio quality assessment (fluency, accuracy, WPM)
|
| 41 |
-
- Visual outfit analysis (YOLO)
|
| 42 |
-
- Semantic similarity scoring
|
| 43 |
-
- Emotion aggregation and fusion
|
| 44 |
-
|
| 45 |
-
**Key Class:** `AnalysisSystem`
|
| 46 |
-
|
| 47 |
-
**Main Method:** `analyze_recording(recording_data, question_data, duration)`
|
| 48 |
-
|
| 49 |
-
---
|
| 50 |
-
|
| 51 |
-
### **Module 3: `scoring_dashboard.py`**
|
| 52 |
-
**Scoring, Hiring Decision, and Results Dashboard**
|
| 53 |
-
|
| 54 |
-
**Responsibilities:**
|
| 55 |
-
- Calculate hiring decision based on metrics
|
| 56 |
-
- Display immediate question results
|
| 57 |
-
- Render performance overview dashboard
|
| 58 |
-
- Question-by-question detailed analysis
|
| 59 |
-
- CSV export functionality
|
| 60 |
-
|
| 61 |
-
**Key Class:** `ScoringDashboard`
|
| 62 |
-
|
| 63 |
-
**Main Methods:**
|
| 64 |
-
- `decide_hire(result)`
|
| 65 |
-
- `render_dashboard(results)`
|
| 66 |
-
|
| 67 |
-
---
|
| 68 |
-
|
| 69 |
-
### **Integration File: `main_app.py`**
|
| 70 |
-
**Main Application Entry Point**
|
| 71 |
-
|
| 72 |
-
**Responsibilities:**
|
| 73 |
-
- Load all AI models (once, with caching)
|
| 74 |
-
- Initialize all three systems
|
| 75 |
-
- Handle Streamlit UI and routing
|
| 76 |
-
- Manage session state
|
| 77 |
-
- Coordinate data flow between modules
|
| 78 |
-
|
| 79 |
-
---
|
| 80 |
-
|
| 81 |
-
## π How Modules Communicate
|
| 82 |
-
|
| 83 |
-
### **Loose Coupling Design**
|
| 84 |
-
|
| 85 |
-
Each module is **completely independent** and communicates through **standardized dictionaries**:
|
| 86 |
-
|
| 87 |
-
```python
|
| 88 |
-
# Module 1 Output β Module 2 Input
|
| 89 |
-
recording_data = {
|
| 90 |
-
'video_path': str,
|
| 91 |
-
'audio_path': str,
|
| 92 |
-
'frames': list,
|
| 93 |
-
'transcript': str,
|
| 94 |
-
'eye_contact_pct': float,
|
| 95 |
-
'blink_count': int,
|
| 96 |
-
'face_box': tuple,
|
| 97 |
-
'violation_detected': bool,
|
| 98 |
-
'violation_reason': str,
|
| 99 |
-
'violations': list
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
# Module 2 Output β Module 3 Input
|
| 103 |
-
analysis_results = {
|
| 104 |
-
'fused_emotions': dict,
|
| 105 |
-
'emotion_scores': dict,
|
| 106 |
-
'accuracy': float,
|
| 107 |
-
'fluency': float,
|
| 108 |
-
'wpm': float,
|
| 109 |
-
'outfit': str,
|
| 110 |
-
'has_valid_data': bool
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
# Module 3 Output
|
| 114 |
-
final_result = {
|
| 115 |
-
'hire_decision': str,
|
| 116 |
-
'hire_reasons': list,
|
| 117 |
-
... (all previous data merged)
|
| 118 |
-
}
|
| 119 |
-
```
|
| 120 |
-
|
| 121 |
-
---
|
| 122 |
-
|
| 123 |
-
## β
Benefits of This Architecture
|
| 124 |
-
|
| 125 |
-
### **1. Independent Development**
|
| 126 |
-
- Modify `recording_system.py` without touching analysis logic
|
| 127 |
-
- Update `analysis_system.py` algorithms without affecting UI
|
| 128 |
-
- Change `scoring_dashboard.py` visualizations without breaking recording
|
| 129 |
-
|
| 130 |
-
### **2. Easy Testing**
|
| 131 |
-
```python
|
| 132 |
-
# Test Module 1 independently
|
| 133 |
-
recording_system = RecordingSystem(models)
|
| 134 |
-
result = recording_system.record_interview(question, 20, callbacks)
|
| 135 |
-
|
| 136 |
-
# Test Module 2 independently
|
| 137 |
-
analysis_system = AnalysisSystem(models)
|
| 138 |
-
analysis = analysis_system.analyze_recording(recording_data, question)
|
| 139 |
-
|
| 140 |
-
# Test Module 3 independently
|
| 141 |
-
dashboard = ScoringDashboard()
|
| 142 |
-
decision, reasons = dashboard.decide_hire(merged_result)
|
| 143 |
-
```
|
| 144 |
-
|
| 145 |
-
### **3. Easy Extension**
|
| 146 |
-
Want to add a new feature? Just modify one module:
|
| 147 |
-
|
| 148 |
-
- **New violation rule** β Edit `recording_system.py`
|
| 149 |
-
- **New emotion detection** β Edit `analysis_system.py`
|
| 150 |
-
- **New chart/metric** β Edit `scoring_dashboard.py`
|
| 151 |
-
|
| 152 |
-
### **4. Reusability**
|
| 153 |
-
Each module can be imported and used in other projects:
|
| 154 |
-
|
| 155 |
-
```python
|
| 156 |
-
# Use only the recording system in another app
|
| 157 |
-
from recording_system import RecordingSystem
|
| 158 |
-
recorder = RecordingSystem(models)
|
| 159 |
-
```
|
| 160 |
-
|
| 161 |
-
---
|
| 162 |
-
|
| 163 |
-
## π How to Run
|
| 164 |
-
|
| 165 |
-
### **1. Install Dependencies**
|
| 166 |
-
```bash
|
| 167 |
-
pip install streamlit opencv-python numpy pandas deepface mediapipe ultralytics sentence-transformers speechrecognition pyaudio
|
| 168 |
-
```
|
| 169 |
-
|
| 170 |
-
### **2. Run the Application**
|
| 171 |
-
```bash
|
| 172 |
-
streamlit run main_app.py
|
| 173 |
-
```
|
| 174 |
-
|
| 175 |
-
### **3. Project Structure**
|
| 176 |
-
Make sure all 4 files are in the same directory:
|
| 177 |
-
```
|
| 178 |
-
your_folder/
|
| 179 |
-
βββ main_app.py
|
| 180 |
-
βββ recording_system.py
|
| 181 |
-
βββ analysis_system.py
|
| 182 |
-
βββ scoring_dashboard.py
|
| 183 |
-
```
|
| 184 |
-
|
| 185 |
-
---
|
| 186 |
-
|
| 187 |
-
## π§ Customization Guide
|
| 188 |
-
|
| 189 |
-
### **Change Violation Rules**
|
| 190 |
-
Edit `recording_system.py`:
|
| 191 |
-
```python
|
| 192 |
-
# In record_interview() method, adjust thresholds:
|
| 193 |
-
if elapsed > 3.0: # Change from 2.0 to 3.0 seconds
|
| 194 |
-
self.violation_detected = True
|
| 195 |
-
```
|
| 196 |
-
|
| 197 |
-
### **Change Analysis Algorithms**
|
| 198 |
-
Edit `analysis_system.py`:
|
| 199 |
-
```python
|
| 200 |
-
# In evaluate_english_fluency(), adjust weights:
|
| 201 |
-
combined = (0.4 * alpha_ratio) + (0.3 * len_score) + ...
|
| 202 |
-
```
|
| 203 |
-
|
| 204 |
-
### **Change Scoring Logic**
|
| 205 |
-
Edit `scoring_dashboard.py`:
|
| 206 |
-
```python
|
| 207 |
-
# In decide_hire(), adjust thresholds:
|
| 208 |
-
if pos >= 6: # More strict (was 5)
|
| 209 |
-
decision = "β
Hire"
|
| 210 |
-
```
|
| 211 |
-
|
| 212 |
-
### **Change UI/Dashboard**
|
| 213 |
-
Edit `scoring_dashboard.py` or `main_app.py`:
|
| 214 |
-
```python
|
| 215 |
-
# Add new charts, change colors, modify layout
|
| 216 |
-
```
|
| 217 |
-
|
| 218 |
-
---
|
| 219 |
-
|
| 220 |
-
## π¨ Module Interfaces (API)
|
| 221 |
-
|
| 222 |
-
### **RecordingSystem API**
|
| 223 |
-
```python
|
| 224 |
-
class RecordingSystem:
|
| 225 |
-
def __init__(self, models_dict)
|
| 226 |
-
def record_interview(self, question_data, duration, ui_callbacks) -> dict
|
| 227 |
-
def detect_cheating_items(self, detected_objects) -> list
|
| 228 |
-
def calculate_eye_gaze(self, face_landmarks, frame_shape) -> bool
|
| 229 |
-
def estimate_head_pose(self, face_landmarks, frame_shape) -> tuple
|
| 230 |
-
```
|
| 231 |
-
|
| 232 |
-
### **AnalysisSystem API**
|
| 233 |
-
```python
|
| 234 |
-
class AnalysisSystem:
|
| 235 |
-
def __init__(self, models_dict)
|
| 236 |
-
def analyze_recording(self, recording_data, question_data, duration) -> dict
|
| 237 |
-
def analyze_frame_emotion(self, frame_bgr) -> dict
|
| 238 |
-
def evaluate_answer_accuracy(self, answer, question, ideal) -> float
|
| 239 |
-
def evaluate_english_fluency(self, text) -> float
|
| 240 |
-
def analyze_outfit(self, frame, face_box) -> tuple
|
| 241 |
-
```
|
| 242 |
-
|
| 243 |
-
### **ScoringDashboard API**
|
| 244 |
-
```python
|
| 245 |
-
class ScoringDashboard:
|
| 246 |
-
def __init__(self)
|
| 247 |
-
def decide_hire(self, result) -> tuple
|
| 248 |
-
def render_dashboard(self, results) -> None
|
| 249 |
-
def display_immediate_results(self, result) -> None
|
| 250 |
-
def export_results_csv(self, results) -> str
|
| 251 |
-
```
|
| 252 |
-
|
| 253 |
---
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
- speech_recognition
|
| 263 |
-
|
| 264 |
-
### **Module 2 (analysis_system.py)**
|
| 265 |
-
- cv2 (opencv-python)
|
| 266 |
-
- numpy
|
| 267 |
-
- pandas
|
| 268 |
-
- deepface
|
| 269 |
-
- sentence-transformers
|
| 270 |
-
- ultralytics
|
| 271 |
-
|
| 272 |
-
### **Module 3 (scoring_dashboard.py)**
|
| 273 |
-
- streamlit
|
| 274 |
-
- numpy
|
| 275 |
-
- pandas
|
| 276 |
-
|
| 277 |
-
### **Main App (main_app.py)**
|
| 278 |
-
- streamlit
|
| 279 |
-
- All dependencies from modules 1-3
|
| 280 |
-
|
| 281 |
---
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
Each module handles its own errors:
|
| 286 |
-
|
| 287 |
-
- **Module 1**: Returns `{'error': 'message'}` if camera fails
|
| 288 |
-
- **Module 2**: Returns default values (0.0) if analysis fails
|
| 289 |
-
- **Module 3**: Handles missing data gracefully in UI
|
| 290 |
-
|
| 291 |
-
The main app checks for errors and displays appropriate messages.
|
| 292 |
-
|
| 293 |
-
---
|
| 294 |
-
|
| 295 |
-
## π Data Flow Diagram
|
| 296 |
-
|
| 297 |
-
```
|
| 298 |
-
βββββββββββββββββββ
|
| 299 |
-
β main_app.py β
|
| 300 |
-
β (Orchestrator) β
|
| 301 |
-
ββββββββββ¬βββββββββ
|
| 302 |
-
β
|
| 303 |
-
ββββΊ 1. Load Models (cached)
|
| 304 |
-
β
|
| 305 |
-
ββββΊ 2. RecordingSystem.record_interview()
|
| 306 |
-
β β
|
| 307 |
-
β ββββΊ Returns: recording_data
|
| 308 |
-
β
|
| 309 |
-
ββββΊ 3. AnalysisSystem.analyze_recording(recording_data)
|
| 310 |
-
β β
|
| 311 |
-
β ββββΊ Returns: analysis_results
|
| 312 |
-
β
|
| 313 |
-
ββββΊ 4. Merge recording_data + analysis_results
|
| 314 |
-
β
|
| 315 |
-
ββββΊ 5. ScoringDashboard.decide_hire(merged_result)
|
| 316 |
-
β
|
| 317 |
-
ββββΊ Returns: (decision, reasons)
|
| 318 |
-
```
|
| 319 |
-
|
| 320 |
-
---
|
| 321 |
-
|
| 322 |
-
## π‘ Best Practices
|
| 323 |
-
|
| 324 |
-
1. **Never modify dictionary keys** between modules - this breaks compatibility
|
| 325 |
-
2. **Always provide default values** in case of missing data
|
| 326 |
-
3. **Use type hints** when adding new methods
|
| 327 |
-
4. **Test each module independently** before integration
|
| 328 |
-
5. **Keep UI logic in main_app.py** or scoring_dashboard.py only
|
| 329 |
-
|
| 330 |
-
---
|
| 331 |
-
|
| 332 |
-
## π Version History
|
| 333 |
-
|
| 334 |
-
- **v2.0**: Modular architecture with 3 independent systems
|
| 335 |
-
- **v1.0**: Monolithic single-file application
|
| 336 |
-
|
| 337 |
-
---
|
| 338 |
-
|
| 339 |
-
## π€ Contributing
|
| 340 |
-
|
| 341 |
-
When adding features:
|
| 342 |
-
|
| 343 |
-
1. Identify which module it belongs to
|
| 344 |
-
2. Add method to that module only
|
| 345 |
-
3. Update the module's docstrings
|
| 346 |
-
4. Test independently before integration
|
| 347 |
-
5. Update this README if adding new APIs
|
| 348 |
-
|
| 349 |
-
---
|
| 350 |
-
|
| 351 |
-
## π§ Support
|
| 352 |
-
|
| 353 |
-
For questions about:
|
| 354 |
-
- **Recording issues** β Check `recording_system.py`
|
| 355 |
-
- **Analysis issues** β Check `analysis_system.py`
|
| 356 |
-
- **UI/Dashboard issues** β Check `scoring_dashboard.py` or `main_app.py`
|
| 357 |
-
|
| 358 |
-
---
|
| 359 |
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
This is a Streamlit-based Interview Assistant app deployed on **Hugging Face Spaces**.
|
| 15 |
+
It helps users interact through an intuitive web interface built with Streamlit.
|