-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
133 lines (122 loc) · 7.23 KB
/
index.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import {process} from '/env'
import { Configuration, OpenAIApi } from 'openai'
const setupInputContainer = document.getElementById('setup-input-container')
const businessManText = document.getElementById('business-man-text')
const businessManPose = document.getElementById('business-man-pose')
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY
})
const openai = new OpenAIApi(configuration)
document.getElementById("send-btn").addEventListener("click", () => {
const setupTextarea = document.getElementById('setup-textarea')
if (setupTextarea.value) {
const userInput = setupTextarea.value
setupInputContainer.innerHTML = `<img src="images/loading.svg" class="loading" id="loading">`
businessManText.innerText = `Ok, just wait a second while my digital brain digests that...`
fetchBotReply(userInput)
fetchSynopsis(userInput)
}
})
async function fetchBotReply(outline) {
const response = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `Generate a short message to enthusiastically say an outline sounds interesting and that you need some minutes to think about it.
###
outline: Two dogs fall in love and move to Hawaii to learn to surf.
message: I'll need to think about that. But your idea is amazing! I love the bit about Hawaii!
###
outline: A plane crashes in the jungle and the passengers have to walk 1000km to safety.
message: I'll spend a few moments considering that. But I love your idea!! A disaster movie in the jungle!
###
outline: A group of corrupt lawyers try to send an innocent woman to jail.
message: Wow that is awesome! Corrupt lawyers, huh? Give me a few moments to think!
###
outline: ${outline}
message:
`,
max_tokens: 60
})
businessManText.innerText = response.data.choices[0].text.trim()
businessManPose.src = "./images/businessman_pointing.png"
}
async function fetchSynopsis(outline) {
const response = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `Generate an engaging, professional and marketable movie synopsis based on an outline. The synopsis should include actors names in brackets after each character. Choose actors that would be ideal for this role.
###
outline: An Indian agent races against a doomsday clock as a ruthless mercenary, with a bitter vendetta, mounts an apocalyptic attack against the country.
synopsis: Indian RAW agent "Pathaan" (Shah Rukh Khan) gets to know of a major impending attack against India, mounted by a mercenary group led by the ruthless enigma Jim (John Abraham), who has a history of his own. With the doomsday clock ticking away and an agent Rubai (Deepika Padukone) his only possible ally, Pathaan must fight countless betrayals and deal with destruction as he takes on Jim. ###
outline: ${outline}
synopsis:
`,
max_tokens: 700
})
const synopsis = response.data.choices[0].text.trim()
document.getElementById('output-text').innerText = synopsis
fetchTitle(synopsis)
fetchStars(synopsis)
}
async function fetchTitle(synopsis) {
const response = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `Generate a catchy movie title for this synopsis: ${synopsis}`,
max_tokens: 25,
temperature: 0.5
})
const title = response.data.choices[0].text.trim()
document.getElementById('output-title').innerText = title
fetchImagePromt(title, synopsis)
}
async function fetchStars(synopsis){
const response = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `Extract the names in brackets from the synopsis.
###
synopsis: Indian RAW agent "Pathaan" (Shah Rukh Khan) gets to know of a major impending attack against India, mounted by a mercenary group led by the ruthless enigma Jim (John Abraham), who has a history of his own. With the doomsday clock ticking away and an agent Rubai (Deepika Padukone) his only possible ally, Pathaan must fight countless betrayals and deal with destruction as he takes on Jim.
names: Shah Rukh Khan, John Abraham, Deepika Padukone
###
synopsis: ${synopsis}
names:
`,
max_tokens: 30
})
document.getElementById('output-stars').innerText = response.data.choices[0].text.trim()
}
async function fetchImagePromt(title, synopsis){
const response = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `Give a short description of an image which could be used to advertise a movie based on a title and synopsis. The description should be rich in visual detail but contain no names.
###
title: Love's Time Warp
synopsis: When scientist and time traveller Wendy (Emma Watson) is sent back to the 1920s to assassinate a future dictator, she never expected to fall in love with them. As Wendy infiltrates the dictator's inner circle, she soon finds herself torn between her mission and her growing feelings for the leader (Brie Larson). With the help of a mysterious stranger from the future (Josh Brolin), Wendy must decide whether to carry out her mission or follow her heart. But the choices she makes in the 1920s will have far-reaching consequences that reverberate through the ages.
image description: A silhouetted figure stands in the shadows of a 1920s speakeasy, her face turned away from the camera. In the background, two people are dancing in the dim light, one wearing a flapper-style dress and the other wearing a dapper suit. A semi-transparent image of war is super-imposed over the scene.
###
title: zero Earth
synopsis: When bodyguard Kob (Daniel Radcliffe) is recruited by the United Nations to save planet Earth from the sinister Simm (John Malkovich), an alien lord with a plan to take over the world, he reluctantly accepts the challenge. With the help of his loyal sidekick, a brave and resourceful hamster named Gizmo (Gaten Matarazzo), Kob embarks on a perilous mission to destroy Simm. Along the way, he discovers a newfound courage and strength as he battles Simm's merciless forces. With the fate of the world in his hands, Kob must find a way to defeat the alien lord and save the planet.
image description: A tired and bloodied bodyguard and hamster standing atop a tall skyscraper, looking out over a vibrant cityscape, with a rainbow in the sky above them.
###
title: ${title}
synopsis: ${synopsis}
image description:
`,
temperature: 0.8,
max_tokens: 100
})
fetchImageUrl(response.data.choices[0].text.trim())
}
async function fetchImageUrl(imagePrompt){
const response = await openai.createImage({
prompt: `${imagePrompt}. There should be no text in this image.`,
n: 1,
size: '256x256',
response_format: 'url'
})
document.getElementById('output-img-container').innerHTML = `<img src="${response.data.data[0].url}">`
setupInputContainer.innerHTML = `<button id="view-pitch-btn" class="view-pitch-btn">View Pitch</button>`
document.getElementById('view-pitch-btn').addEventListener('click', ()=>{
document.getElementById('setup-container').style.display = 'none'
document.getElementById('output-container').style.display = 'flex'
})
businessManText.innerText = `Wow, brace yourself for this incredible movie idea! Get ready to be blown away by its awesomeness!`
businessManPose.src="./images/businessman_pitch.png"
}