Spaces:
Running
Running
colab-user commited on
Commit ·
22bc992
1
Parent(s): 1ef53da
fix response api
Browse files- app/api/routes.py +10 -3
- app/services/processor.py +8 -5
- app/static/js/app.js +6 -0
app/api/routes.py
CHANGED
|
@@ -15,6 +15,7 @@ from app.services.audio_processor import AudioProcessor, AudioProcessingError
|
|
| 15 |
from app.services.transcription import TranscriptionService, AVAILABLE_MODELS
|
| 16 |
from app.services.diarization import DiarizationService
|
| 17 |
from app.services.processor import Processor
|
|
|
|
| 18 |
|
| 19 |
logger = logging.getLogger(__name__)
|
| 20 |
settings = get_settings()
|
|
@@ -97,15 +98,20 @@ async def transcribe_audio(
|
|
| 97 |
with csv_path.open("w", newline="", encoding="utf-8-sig") as f:
|
| 98 |
writer = csv.DictWriter(
|
| 99 |
f,
|
| 100 |
-
fieldnames=["start", "end", "speaker", "text"],
|
| 101 |
)
|
| 102 |
writer.writeheader()
|
| 103 |
for seg in result.segments:
|
|
|
|
|
|
|
|
|
|
| 104 |
writer.writerow({
|
| 105 |
"start": round(seg.start, 2),
|
| 106 |
"end": round(seg.end, 2),
|
| 107 |
"speaker": roles.get(seg.speaker, seg.speaker),
|
| 108 |
"text": seg.text,
|
|
|
|
|
|
|
| 109 |
})
|
| 110 |
|
| 111 |
|
|
@@ -122,7 +128,8 @@ async def transcribe_audio(
|
|
| 122 |
"speaker": seg.speaker,
|
| 123 |
"role": seg.role,
|
| 124 |
"text": seg.text,
|
| 125 |
-
"emotion": seg.emotion
|
|
|
|
| 126 |
}
|
| 127 |
for seg in result.segments
|
| 128 |
],
|
|
@@ -136,7 +143,7 @@ async def transcribe_audio(
|
|
| 136 |
{
|
| 137 |
"time": p.time,
|
| 138 |
"emotion": p.emotion,
|
| 139 |
-
"icon": p.icon
|
| 140 |
}
|
| 141 |
for p in (result.emotion_timeline or [])
|
| 142 |
],
|
|
|
|
| 15 |
from app.services.transcription import TranscriptionService, AVAILABLE_MODELS
|
| 16 |
from app.services.diarization import DiarizationService
|
| 17 |
from app.services.processor import Processor
|
| 18 |
+
from app.services.emo import EmotionService
|
| 19 |
|
| 20 |
logger = logging.getLogger(__name__)
|
| 21 |
settings = get_settings()
|
|
|
|
| 98 |
with csv_path.open("w", newline="", encoding="utf-8-sig") as f:
|
| 99 |
writer = csv.DictWriter(
|
| 100 |
f,
|
| 101 |
+
fieldnames=["start", "end", "speaker", "text", "emotion", "icon"],
|
| 102 |
)
|
| 103 |
writer.writeheader()
|
| 104 |
for seg in result.segments:
|
| 105 |
+
emotion = seg.emotion or ""
|
| 106 |
+
icon = EmotionService.meta.get(emotion, {}).get("emoji", "") if emotion else ""
|
| 107 |
+
|
| 108 |
writer.writerow({
|
| 109 |
"start": round(seg.start, 2),
|
| 110 |
"end": round(seg.end, 2),
|
| 111 |
"speaker": roles.get(seg.speaker, seg.speaker),
|
| 112 |
"text": seg.text,
|
| 113 |
+
"emotion": emotion,
|
| 114 |
+
"icon": icon
|
| 115 |
})
|
| 116 |
|
| 117 |
|
|
|
|
| 128 |
"speaker": seg.speaker,
|
| 129 |
"role": seg.role,
|
| 130 |
"text": seg.text,
|
| 131 |
+
"emotion": seg.emotion,
|
| 132 |
+
"icon": EmotionService.meta.get(seg.emotion, {}).get("emoji", "") if seg.emotion else ""
|
| 133 |
}
|
| 134 |
for seg in result.segments
|
| 135 |
],
|
|
|
|
| 143 |
{
|
| 144 |
"time": p.time,
|
| 145 |
"emotion": p.emotion,
|
| 146 |
+
"icon": p.icon
|
| 147 |
}
|
| 148 |
for p in (result.emotion_timeline or [])
|
| 149 |
],
|
app/services/processor.py
CHANGED
|
@@ -17,7 +17,6 @@ from app.services.alignment import AlignmentService
|
|
| 17 |
from app.services.transcription import WordTimestamp
|
| 18 |
from app.services.emo import EmotionService
|
| 19 |
|
| 20 |
-
|
| 21 |
from app.services.diarization import DiarizationService, SpeakerSegment, DiarizationResult
|
| 22 |
|
| 23 |
logger = logging.getLogger(__name__)
|
|
@@ -41,7 +40,6 @@ class EmotionPoint:
|
|
| 41 |
emotion: str
|
| 42 |
icon: Optional[str]
|
| 43 |
|
| 44 |
-
|
| 45 |
@dataclass
|
| 46 |
class EmotionChange:
|
| 47 |
time: float
|
|
@@ -605,8 +603,10 @@ class Processor:
|
|
| 605 |
role = seg.role or "UNKNOWN"
|
| 606 |
|
| 607 |
speaker_icon = speaker_icons.get(seg.speaker, "⚪")
|
|
|
|
|
|
|
| 608 |
lines.append(
|
| 609 |
-
f"{ts} {speaker_icon} [{seg.speaker}|{role}] {seg.text}"
|
| 610 |
)
|
| 611 |
|
| 612 |
return "\n".join(lines)
|
|
@@ -618,7 +618,10 @@ class Processor:
|
|
| 618 |
|
| 619 |
output = StringIO()
|
| 620 |
writer = csv.writer(output)
|
| 621 |
-
writer.writerow(["start", "end", "speaker", "text"])
|
| 622 |
for seg in segments:
|
| 623 |
-
|
|
|
|
|
|
|
|
|
|
| 624 |
return output.getvalue()
|
|
|
|
| 17 |
from app.services.transcription import WordTimestamp
|
| 18 |
from app.services.emo import EmotionService
|
| 19 |
|
|
|
|
| 20 |
from app.services.diarization import DiarizationService, SpeakerSegment, DiarizationResult
|
| 21 |
|
| 22 |
logger = logging.getLogger(__name__)
|
|
|
|
| 40 |
emotion: str
|
| 41 |
icon: Optional[str]
|
| 42 |
|
|
|
|
| 43 |
@dataclass
|
| 44 |
class EmotionChange:
|
| 45 |
time: float
|
|
|
|
| 603 |
role = seg.role or "UNKNOWN"
|
| 604 |
|
| 605 |
speaker_icon = speaker_icons.get(seg.speaker, "⚪")
|
| 606 |
+
emotion = seg.emotion or ""
|
| 607 |
+
emotion_icon = EmotionService.meta.get(emotion, {}).get("emoji", "") if emotion else ""
|
| 608 |
lines.append(
|
| 609 |
+
f"{ts} {speaker_icon} [{seg.speaker}|{role}] {seg.text} {emotion_icon} {emotion}"
|
| 610 |
)
|
| 611 |
|
| 612 |
return "\n".join(lines)
|
|
|
|
| 618 |
|
| 619 |
output = StringIO()
|
| 620 |
writer = csv.writer(output)
|
| 621 |
+
writer.writerow(["start", "end", "speaker", "text", "emotion", "icon"])
|
| 622 |
for seg in segments:
|
| 623 |
+
emotion = seg.emotion or ""
|
| 624 |
+
icon = EmotionService.meta.get(emotion, {}).get("emoji", "") if emotion else ""
|
| 625 |
+
|
| 626 |
+
writer.writerow([round(seg.start, 3), round(seg.end, 3), seg.speaker, seg.text, emotion, icon])
|
| 627 |
return output.getvalue()
|
app/static/js/app.js
CHANGED
|
@@ -246,6 +246,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 246 |
segments.forEach((segment) => {
|
| 247 |
const role = segment.role || 'UNKNOWN';
|
| 248 |
|
|
|
|
|
|
|
|
|
|
| 249 |
if (!(role in roleColors)) {
|
| 250 |
colorIndex++;
|
| 251 |
roleColors[role] = `speaker-${Math.min(colorIndex, 5)}`;
|
|
@@ -268,6 +271,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 268 |
</span>
|
| 269 |
</div>
|
| 270 |
<p class="segment-text">${text}</p>
|
|
|
|
|
|
|
|
|
|
| 271 |
`;
|
| 272 |
|
| 273 |
elements.transcriptContainer.appendChild(segmentEl);
|
|
|
|
| 246 |
segments.forEach((segment) => {
|
| 247 |
const role = segment.role || 'UNKNOWN';
|
| 248 |
|
| 249 |
+
const emotion = segment.emotion || 'Neutral';
|
| 250 |
+
const icon = segment.icon || '😐';
|
| 251 |
+
|
| 252 |
if (!(role in roleColors)) {
|
| 253 |
colorIndex++;
|
| 254 |
roleColors[role] = `speaker-${Math.min(colorIndex, 5)}`;
|
|
|
|
| 271 |
</span>
|
| 272 |
</div>
|
| 273 |
<p class="segment-text">${text}</p>
|
| 274 |
+
<div class="segment-emotion">
|
| 275 |
+
${icon} ${escapeHtml(emotion)}
|
| 276 |
+
</div>
|
| 277 |
`;
|
| 278 |
|
| 279 |
elements.transcriptContainer.appendChild(segmentEl);
|