-
Notifications
You must be signed in to change notification settings - Fork 314
Expand file tree
/
Copy pathapp.js
More file actions
89 lines (77 loc) · 2.49 KB
/
app.js
File metadata and controls
89 lines (77 loc) · 2.49 KB
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
// <complete_code>
// <imports>
import { FoundryLocalManager } from 'foundry-local-sdk';
import { fileURLToPath } from 'url';
import path from 'path';
// </imports>
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// <init>
// Initialize the Foundry Local SDK
const manager = FoundryLocalManager.create({
appName: 'foundry_local_samples',
logLevel: 'info'
});
// </init>
// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');
// <transcription>
// Load the speech-to-text model
const speechModel = await manager.catalog.getModel('whisper-tiny');
await speechModel.download((progress) => {
process.stdout.write(
`\rDownloading speech model: ${progress.toFixed(2)}%`
);
});
console.log('\nSpeech model downloaded.');
await speechModel.load();
console.log('Speech model loaded.');
// Transcribe the audio file
const audioClient = speechModel.createAudioClient();
const transcription = await audioClient.transcribe(
path.join(__dirname, 'meeting-notes.wav')
);
console.log(`\nTranscription:\n${transcription.text}`);
// Unload the speech model to free memory
await speechModel.unload();
// </transcription>
// <summarization>
// Load the chat model for summarization
const chatModel = await manager.catalog.getModel('qwen2.5-0.5b');
await chatModel.download((progress) => {
process.stdout.write(
`\rDownloading chat model: ${progress.toFixed(2)}%`
);
});
console.log('\nChat model downloaded.');
await chatModel.load();
console.log('Chat model loaded.');
// Summarize the transcription into organized notes
const chatClient = chatModel.createChatClient();
const messages = [
{
role: 'system',
content: 'You are a note-taking assistant. Summarize ' +
'the following transcription into organized, ' +
'concise notes with bullet points.'
},
{
role: 'user',
content: transcription.text
}
];
const response = await chatClient.completeChat(messages);
const summary = response.choices[0]?.message?.content;
console.log(`\nSummary:\n${summary}`);
// Clean up
await chatModel.unload();
console.log('\nDone. Models unloaded.');
// </summarization>
// </complete_code>