59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
import asyncio
|
|
import urllib.request
|
|
import json
|
|
import sys
|
|
import hybrid_diarization
|
|
|
|
async def summarize_with_qwen(conversation_text):
|
|
print("\n[*] Sending to local Qwen2.5 for summarization...")
|
|
prompt = f"Please summarize the following conversation:\n\n{conversation_text}\n\nSummary:"
|
|
|
|
data = json.dumps({
|
|
"model": "qwen2.5",
|
|
"prompt": prompt,
|
|
"stream": False
|
|
}).encode('utf-8')
|
|
|
|
req = urllib.request.Request(
|
|
"http://localhost:11434/api/generate",
|
|
data=data,
|
|
headers={'Content-Type': 'application/json'}
|
|
)
|
|
|
|
try:
|
|
with urllib.request.urlopen(req) as response:
|
|
result = json.loads(response.read().decode('utf-8'))
|
|
return result.get("response", "")
|
|
except Exception as e:
|
|
return f"Exception calling Ollama: {e}"
|
|
|
|
async def main():
|
|
audio_path = "test.wav"
|
|
print(f"[*] Calling Sarvam STT API for transcription... (with_timestamps=true)")
|
|
sarvam_res = hybrid_diarization.get_sarvam_transcript(audio_path)
|
|
|
|
print(f"[*] Running local Nvidia Sortformer model for diarization...")
|
|
nemo_segments = hybrid_diarization.get_nemo_segments(audio_path)
|
|
|
|
print(f"[*] Aligning Sarvam transcript words with Nvidia speaker segments...")
|
|
dialogue = hybrid_diarization.align_words_to_segments(sarvam_res, nemo_segments)
|
|
|
|
print("\n--- FINAL HYBRID DIALOGUE ---\n")
|
|
conv_lines = []
|
|
for spk, text in dialogue:
|
|
line = f"**{spk}:** {text}"
|
|
print(line)
|
|
conv_lines.append(line)
|
|
|
|
conversation_text = "\n".join(conv_lines)
|
|
|
|
if conversation_text:
|
|
summary = await summarize_with_qwen(conversation_text)
|
|
print("\n--- SUMMARY (Qwen2.5) ---\n")
|
|
print(summary)
|
|
else:
|
|
print("\nNo dialogue found to summarize.")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|