Spaces:
Running
Running
colab-user commited on
Commit ·
d8fc038
1
Parent(s): 502a6a2
fix processor & UI
Browse files- app/services/processor.py +18 -13
- app/static/js/app.js +17 -7
app/services/processor.py
CHANGED
|
@@ -195,21 +195,28 @@ class Processor:
|
|
| 195 |
|
| 196 |
speakers = list(speaker_map.values())
|
| 197 |
|
| 198 |
-
|
| 199 |
-
# 6. Infer role ONLY if diarization did not provide
|
| 200 |
speaker_duration = defaultdict(float)
|
| 201 |
for seg in refined_segments:
|
| 202 |
-
speaker_duration[
|
| 203 |
|
|
|
|
| 204 |
|
| 205 |
if speaker_duration:
|
| 206 |
-
|
|
|
|
| 207 |
roles = {
|
| 208 |
-
|
| 209 |
-
for
|
| 210 |
}
|
| 211 |
else:
|
| 212 |
-
roles = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
|
| 215 |
|
|
@@ -261,7 +268,7 @@ class Processor:
|
|
| 261 |
start=seg.start,
|
| 262 |
end=seg.end,
|
| 263 |
speaker=label,
|
| 264 |
-
role=roles
|
| 265 |
text=text.strip(),
|
| 266 |
)
|
| 267 |
)
|
|
@@ -272,28 +279,26 @@ class Processor:
|
|
| 272 |
start=0.0,
|
| 273 |
end=duration,
|
| 274 |
speaker=speakers[0],
|
| 275 |
-
role=roles
|
| 276 |
text="(No speech detected)"
|
| 277 |
)
|
| 278 |
]
|
| 279 |
|
| 280 |
processing_time = time.time() - t0
|
| 281 |
-
speaker_count=len(speakers)
|
| 282 |
|
| 283 |
txt_content = cls._generate_txt(
|
| 284 |
processed_segments,
|
| 285 |
-
|
| 286 |
processing_time,
|
| 287 |
duration,
|
| 288 |
roles
|
| 289 |
)
|
| 290 |
|
| 291 |
-
|
| 292 |
csv_content = cls._generate_csv(processed_segments)
|
| 293 |
|
| 294 |
return ProcessingResult(
|
| 295 |
segments=processed_segments,
|
| 296 |
-
speaker_count=
|
| 297 |
duration=duration,
|
| 298 |
processing_time=processing_time,
|
| 299 |
speakers=speakers,
|
|
|
|
| 195 |
|
| 196 |
speakers = list(speaker_map.values())
|
| 197 |
|
| 198 |
+
# 6. NORMALIZE ROLES
|
|
|
|
| 199 |
speaker_duration = defaultdict(float)
|
| 200 |
for seg in refined_segments:
|
| 201 |
+
speaker_duration[seg.speaker] += seg.end - seg.start
|
| 202 |
|
| 203 |
+
logger.info(f"speaker_duration(raw) = {speaker_duration}")
|
| 204 |
|
| 205 |
if speaker_duration:
|
| 206 |
+
agent_raw = max(speaker_duration, key=speaker_duration.get)
|
| 207 |
+
|
| 208 |
roles = {
|
| 209 |
+
speaker_map[spk]: ("NV" if spk == agent_raw else "KH")
|
| 210 |
+
for spk in speaker_duration
|
| 211 |
}
|
| 212 |
else:
|
| 213 |
+
roles = {}
|
| 214 |
+
|
| 215 |
+
# Default fallback
|
| 216 |
+
for label in speakers:
|
| 217 |
+
roles.setdefault(label, "KH")
|
| 218 |
+
|
| 219 |
+
logger.info(f"roles(mapped) = {roles}")
|
| 220 |
|
| 221 |
|
| 222 |
|
|
|
|
| 268 |
start=seg.start,
|
| 269 |
end=seg.end,
|
| 270 |
speaker=label,
|
| 271 |
+
role=roles[label],
|
| 272 |
text=text.strip(),
|
| 273 |
)
|
| 274 |
)
|
|
|
|
| 279 |
start=0.0,
|
| 280 |
end=duration,
|
| 281 |
speaker=speakers[0],
|
| 282 |
+
role=roles[speakers[0]],
|
| 283 |
text="(No speech detected)"
|
| 284 |
)
|
| 285 |
]
|
| 286 |
|
| 287 |
processing_time = time.time() - t0
|
|
|
|
| 288 |
|
| 289 |
txt_content = cls._generate_txt(
|
| 290 |
processed_segments,
|
| 291 |
+
len(speakers),
|
| 292 |
processing_time,
|
| 293 |
duration,
|
| 294 |
roles
|
| 295 |
)
|
| 296 |
|
|
|
|
| 297 |
csv_content = cls._generate_csv(processed_segments)
|
| 298 |
|
| 299 |
return ProcessingResult(
|
| 300 |
segments=processed_segments,
|
| 301 |
+
speaker_count=len(speakers),
|
| 302 |
duration=duration,
|
| 303 |
processing_time=processing_time,
|
| 304 |
speakers=speakers,
|
app/static/js/app.js
CHANGED
|
@@ -207,7 +207,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 207 |
|
| 208 |
function displayResults(result) {
|
| 209 |
// Update metadata
|
| 210 |
-
elements.speakerCount.textContent
|
|
|
|
| 211 |
elements.durationInfo.textContent = formatDuration(result.duration);
|
| 212 |
elements.processingTime.textContent = `${result.processing_time}s`;
|
| 213 |
|
|
@@ -229,19 +230,27 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 229 |
let colorIndex = 0;
|
| 230 |
|
| 231 |
segments.forEach((segment) => {
|
| 232 |
-
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
colorIndex++;
|
| 235 |
-
speakerColors[
|
| 236 |
}
|
| 237 |
|
| 238 |
const segmentEl = document.createElement('div');
|
| 239 |
-
segmentEl.className = `segment ${speakerColors[
|
| 240 |
|
| 241 |
segmentEl.innerHTML = `
|
| 242 |
<div class="segment-header">
|
| 243 |
-
<span class="segment-speaker"
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
</div>
|
| 246 |
<p class="segment-text">${escapeHtml(segment.text)}</p>
|
| 247 |
`;
|
|
@@ -250,6 +259,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 250 |
});
|
| 251 |
}
|
| 252 |
|
|
|
|
| 253 |
function formatTime(seconds) {
|
| 254 |
const h = Math.floor(seconds / 3600);
|
| 255 |
const m = Math.floor((seconds % 3600) / 60);
|
|
|
|
| 207 |
|
| 208 |
function displayResults(result) {
|
| 209 |
// Update metadata
|
| 210 |
+
elements.speakerCount.textContent =`${result.speaker_count} speaker${result.speaker_count !== 1 ? 's' : ''}`;
|
| 211 |
+
|
| 212 |
elements.durationInfo.textContent = formatDuration(result.duration);
|
| 213 |
elements.processingTime.textContent = `${result.processing_time}s`;
|
| 214 |
|
|
|
|
| 230 |
let colorIndex = 0;
|
| 231 |
|
| 232 |
segments.forEach((segment) => {
|
| 233 |
+
|
| 234 |
+
const displayName = segment.role
|
| 235 |
+
? segment.role
|
| 236 |
+
: segment.speaker;
|
| 237 |
+
|
| 238 |
+
if (!(displayName in speakerColors)) {
|
| 239 |
colorIndex++;
|
| 240 |
+
speakerColors[displayName] = `speaker-${Math.min(colorIndex, 5)}`;
|
| 241 |
}
|
| 242 |
|
| 243 |
const segmentEl = document.createElement('div');
|
| 244 |
+
segmentEl.className = `segment ${speakerColors[displayName]}`;
|
| 245 |
|
| 246 |
segmentEl.innerHTML = `
|
| 247 |
<div class="segment-header">
|
| 248 |
+
<span class="segment-speaker">
|
| 249 |
+
${escapeHtml(displayName)}
|
| 250 |
+
</span>
|
| 251 |
+
<span class="segment-time">
|
| 252 |
+
${formatTime(segment.start)} - ${formatTime(segment.end)}
|
| 253 |
+
</span>
|
| 254 |
</div>
|
| 255 |
<p class="segment-text">${escapeHtml(segment.text)}</p>
|
| 256 |
`;
|
|
|
|
| 259 |
});
|
| 260 |
}
|
| 261 |
|
| 262 |
+
|
| 263 |
function formatTime(seconds) {
|
| 264 |
const h = Math.floor(seconds / 3600);
|
| 265 |
const m = Math.floor((seconds % 3600) / 60);
|