File size: 9,335 Bytes
f2dd765
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# AI Interview System - Modular Architecture

## πŸ“ Project Structure

```

ai_interview_system/

β”‚

β”œβ”€β”€ main_app.py              # Main integration file (run this)

β”œβ”€β”€ recording_system.py      # Module 1: Recording & Violation Detection

β”œβ”€β”€ analysis_system.py       # Module 2: Multi-Modal Analysis

β”œβ”€β”€ scoring_dashboard.py     # Module 3: Scoring & Dashboard

└── README.md               # This file

```

## 🎯 Module Overview

### **Module 1: `recording_system.py`**

**Real-Time Interview Recording and Violation Detection System**



**Responsibilities:**

- Video and audio recording

- Real-time violation detection (multiple people, looking away, no face, cheating items)

- Eye contact tracking

- Blink detection

- Head pose estimation

- Lighting analysis

- Audio transcription



**Key Class:** `RecordingSystem`



**Main Method:** `record_interview(question_data, duration, ui_callbacks)`



---



### **Module 2: `analysis_system.py`**

**Multi-Modal Analysis System**



**Responsibilities:**

- Facial emotion analysis (DeepFace)

- Audio quality assessment (fluency, accuracy, WPM)

- Visual outfit analysis (YOLO)

- Semantic similarity scoring

- Emotion aggregation and fusion



**Key Class:** `AnalysisSystem`



**Main Method:** `analyze_recording(recording_data, question_data, duration)`

---

### **Module 3: `scoring_dashboard.py`**

**Scoring, Hiring Decision, and Results Dashboard**



**Responsibilities:**

- Calculate hiring decision based on metrics

- Display immediate question results

- Render performance overview dashboard

- Question-by-question detailed analysis

- CSV export functionality



**Key Class:** `ScoringDashboard`



**Main Methods:** 

- `decide_hire(result)`

- `render_dashboard(results)`



---



### **Integration File: `main_app.py`**
**Main Application Entry Point**

**Responsibilities:**
- Load all AI models (once, with caching)
- Initialize all three systems
- Handle Streamlit UI and routing
- Manage session state
- Coordinate data flow between modules

---

## πŸ”Œ How Modules Communicate

### **Loose Coupling Design**

Each module is **completely independent** and communicates through **standardized dictionaries**:

```python

# Module 1 Output β†’ Module 2 Input

recording_data = {

    'video_path': str,

    'audio_path': str,

    'frames': list,

    'transcript': str,

    'eye_contact_pct': float,

    'blink_count': int,

    'face_box': tuple,

    'violation_detected': bool,

    'violation_reason': str,

    'violations': list

}



# Module 2 Output β†’ Module 3 Input

analysis_results = {

    'fused_emotions': dict,

    'emotion_scores': dict,

    'accuracy': float,

    'fluency': float,

    'wpm': float,

    'outfit': str,

    'has_valid_data': bool

}



# Module 3 Output

final_result = {

    'hire_decision': str,

    'hire_reasons': list,

    ... (all previous data merged)

}

```

---

## βœ… Benefits of This Architecture

### **1. Independent Development**
- Modify `recording_system.py` without touching analysis logic
- Update `analysis_system.py` algorithms without affecting UI
- Change `scoring_dashboard.py` visualizations without breaking recording

### **2. Easy Testing**
```python

# Test Module 1 independently

recording_system = RecordingSystem(models)

result = recording_system.record_interview(question, 20, callbacks)



# Test Module 2 independently

analysis_system = AnalysisSystem(models)

analysis = analysis_system.analyze_recording(recording_data, question)



# Test Module 3 independently

dashboard = ScoringDashboard()

decision, reasons = dashboard.decide_hire(merged_result)

```

### **3. Easy Extension**
Want to add a new feature? Just modify one module:

- **New violation rule** β†’ Edit `recording_system.py`
- **New emotion detection** β†’ Edit `analysis_system.py`
- **New chart/metric** β†’ Edit `scoring_dashboard.py`

### **4. Reusability**
Each module can be imported and used in other projects:

```python

# Use only the recording system in another app

from recording_system import RecordingSystem

recorder = RecordingSystem(models)

```

---

## πŸš€ How to Run

### **1. Install Dependencies**
```bash

pip install streamlit opencv-python numpy pandas deepface mediapipe ultralytics sentence-transformers speechrecognition pyaudio

```

### **2. Run the Application**
```bash

streamlit run main_app.py

```

### **3. Project Structure**
Make sure all 4 files are in the same directory:
```

your_folder/

β”œβ”€β”€ main_app.py

β”œβ”€β”€ recording_system.py

β”œβ”€β”€ analysis_system.py

└── scoring_dashboard.py

```

---

## πŸ”§ Customization Guide

### **Change Violation Rules**
Edit `recording_system.py`:
```python

# In record_interview() method, adjust thresholds:

if elapsed > 3.0:  # Change from 2.0 to 3.0 seconds

    self.violation_detected = True

```

### **Change Analysis Algorithms**
Edit `analysis_system.py`:
```python

# In evaluate_english_fluency(), adjust weights:

combined = (0.4 * alpha_ratio) + (0.3 * len_score) + ...

```

### **Change Scoring Logic**
Edit `scoring_dashboard.py`:
```python

# In decide_hire(), adjust thresholds:

if pos >= 6:  # More strict (was 5)

    decision = "βœ… Hire"

```

### **Change UI/Dashboard**
Edit `scoring_dashboard.py` or `main_app.py`:
```python

# Add new charts, change colors, modify layout

```

---

## 🎨 Module Interfaces (API)

### **RecordingSystem API**
```python

class RecordingSystem:

    def __init__(self, models_dict)

    def record_interview(self, question_data, duration, ui_callbacks) -> dict

    def detect_cheating_items(self, detected_objects) -> list

    def calculate_eye_gaze(self, face_landmarks, frame_shape) -> bool

    def estimate_head_pose(self, face_landmarks, frame_shape) -> tuple

```

### **AnalysisSystem API**
```python

class AnalysisSystem:

    def __init__(self, models_dict)

    def analyze_recording(self, recording_data, question_data, duration) -> dict

    def analyze_frame_emotion(self, frame_bgr) -> dict

    def evaluate_answer_accuracy(self, answer, question, ideal) -> float

    def evaluate_english_fluency(self, text) -> float

    def analyze_outfit(self, frame, face_box) -> tuple

```

### **ScoringDashboard API**
```python

class ScoringDashboard:

    def __init__(self)

    def decide_hire(self, result) -> tuple

    def render_dashboard(self, results) -> None

    def display_immediate_results(self, result) -> None

    def export_results_csv(self, results) -> str

```

---

## πŸ“¦ Dependencies by Module

### **Module 1 (recording_system.py)**

- cv2 (opencv-python)

- numpy

- mediapipe

- ultralytics

- speech_recognition



### **Module 2 (analysis_system.py)**

- cv2 (opencv-python)

- numpy

- pandas

- deepface

- sentence-transformers

- ultralytics



### **Module 3 (scoring_dashboard.py)**

- streamlit

- numpy

- pandas



### **Main App (main_app.py)**

- streamlit

- All dependencies from modules 1-3



---



## πŸ›‘οΈ Error Handling



Each module handles its own errors:



- **Module 1**: Returns `{'error': 'message'}` if camera fails

- **Module 2**: Returns default values (0.0) if analysis fails

- **Module 3**: Handles missing data gracefully in UI



The main app checks for errors and displays appropriate messages.



---



## πŸ”„ Data Flow Diagram



```

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚   main_app.py   β”‚
β”‚  (Orchestrator) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚

         β”œβ”€β”€β–Ί 1. Load Models (cached)

         β”‚

         β”œβ”€β”€β–Ί 2. RecordingSystem.record_interview()

         β”‚         β”‚

         β”‚         └──► Returns: recording_data

         β”‚

         β”œβ”€β”€β–Ί 3. AnalysisSystem.analyze_recording(recording_data)

         β”‚         β”‚

         β”‚         └──► Returns: analysis_results

         β”‚

         β”œβ”€β”€β–Ί 4. Merge recording_data + analysis_results

         β”‚

         └──► 5. ScoringDashboard.decide_hire(merged_result)

                   β”‚

                   └──► Returns: (decision, reasons)

```


---

## πŸ’‘ Best Practices

1. **Never modify dictionary keys** between modules - this breaks compatibility
2. **Always provide default values** in case of missing data
3. **Use type hints** when adding new methods
4. **Test each module independently** before integration
5. **Keep UI logic in main_app.py** or scoring_dashboard.py only



---



## πŸ“ Version History



- **v2.0**: Modular architecture with 3 independent systems

- **v1.0**: Monolithic single-file application



---



## 🀝 Contributing



When adding features:



1. Identify which module it belongs to

2. Add method to that module only

3. Update the module's docstrings

4. Test independently before integration

5. Update this README if adding new APIs



---



## πŸ“§ Support



For questions about:

- **Recording issues** β†’ Check `recording_system.py`
- **Analysis issues** β†’ Check `analysis_system.py`
- **UI/Dashboard issues** β†’ Check `scoring_dashboard.py` or `main_app.py`

---

**Built with ❀️ using Modular Design Principles**