-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_conversation.js
107 lines (85 loc) · 3.04 KB
/
create_conversation.js
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
import {EdenClient} from "eden-sdk";
import {getRandomSample, parseChat} from './utils.js';
import characters from './characters.js';
import openai from 'openai';
import dotenv from 'dotenv';
import fs from 'fs';
dotenv.config()
const eden = new EdenClient();
eden.loginApi(process.env.EDEN_API_KEY, process.env.EDEN_API_SECRET);
const configuration = new openai.Configuration({
apiKey: process.env.OPENAI_API_KEY
});
const gpt3 = new openai.OpenAIApi(configuration);
const topics = [
"how cool Bombay Beach is",
"off-grid solarpunk communities in the desert",
"artificial intelligence and the ultimate nature of reality",
"consciousness and and the simulation",
"DAOs, blockchains, and crypto-art",
"the future of the internet",
"how to make a living as an artist",
"the beauty of mathematics and physics",
"Keynesian and Austrian economics",
"the differences among the various flavors of Buddhism",
]
const allCharacters = ['Czar', 'Delic', 'Marzipan', 'Vanessa', 'Freeman', 'Gene', 'Xander', 'Vincent'];
const selectedCharacters = getRandomSample(allCharacters, 4);
const selectedTopic = getRandomSample(topics, 1)[0];
console.log(selectedTopic, selectedCharacters);
// 1) write prompt
let characterIntro = "";
for (const c of selectedCharacters) {
const character = characters[c];
characterIntro += `${c}, ${character.description}\n`;
}
const prompt = `
I would like you to create a chat conversation between the following four characters.
${characterIntro}
The topic of the conversation is ${selectedTopic}.
Write a conversation between these four characters that is at least 500 words long. It should be formatted as a chat, one line for each message. No one should speak except these four characters.
`;
console.log(prompt);
// 2) generate conversation
let completion = await gpt3.createCompletion({
model: "text-davinci-003",
prompt: prompt,
temperature: 0.9,
max_tokens: 500,
top_p: 1,
frequency_penalty: 0.15,
presence_penalty: 0.1
});
let chat = completion.data.choices[0].text;
let messages = parseChat(chat);
console.log(messages);
// 3) generate videos
let final_videos = [];
for (let message of messages) {
const character = characters[message.speaker];
const audioFiles = character.audioFiles;
const faceFiles = getRandomSample(character.lora, 1);
const faceFile = faceFiles[0];
const audioUrls = await eden.uploadFiles(audioFiles);
const faceUrl = await eden.uploadFile(faceFile);
let ttsResult = await eden.create("tts", {
text: message.message,
voice: "clone",
voice_file_urls: audioUrls,
preset: "high_quality",
});
let videoResult = await eden.create("wav2lip", {
speech_url: ttsResult.uri,
face_url: faceUrl.url,
gfpgan: true,
gfpgan_upscale: 2.0
});
final_videos.push(videoResult.uri);
}
console.log(final_videos);
// write the list to file
const filename = 'output/' + Math.random().toString(36).substring(7) + '.txt';
fs.writeFile(filename, final_videos.join(", "), (err) => {
if (err) throw err;
console.log('The string was successfully written to file.');
});