-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathForm1.cs
More file actions
551 lines (384 loc) · 16.2 KB
/
Copy pathForm1.cs
File metadata and controls
551 lines (384 loc) · 16.2 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenAI_API;
using OpenAI_API.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using System.Runtime.Remoting.Messaging;
using System.Security.Cryptography.X509Certificates;
using System.IO;
namespace ScriptHelper
{
public partial class Form1 : Form
{
public OpenAIAPI api;
int NotesTextKount = 0;
List<SceneObj> scenes;
List<SceneObj> scenesinscenes;
SceneObj scene;
MovieObj myMovie = new MovieObj();
string gptModel = "gpt-3.5-turbo";
// Set up the ListBox
public Form1()
{
InitializeComponent();
api = new OpenAIAPI(getOpenAIPassword());
SelectGPT35.Checked = true;
// makeProtoTypeScenes();
ScenesList.DataSource = scenes;
SceneInScenesList.DataSource = scenesinscenes;
ScenesList.DisplayMember = "Title";
MovieHintText.Text = makePrototypeMovieHint();
myMovie.movieHintText = MovieHintText.Text;
Movie.SelectedIndexChanged += Movie_SelectedIndexChanged;
}
private string getOpenAIPassword()
{
string path = @"D:\OOAIpwd.txt";
using (StreamReader sr = new StreamReader(path))
{
// Read the first line from the file
string pwd = sr.ReadLine();
return pwd;
}
}
private void Form1_Load(object sender, EventArgs e)
{
// UtilsGPT module = new UtilsGPT();
// module.UpdateError(this);
}
private void Movie_SelectedIndexChanged(object sender, EventArgs e)
{
TabControl tabControl = sender as TabControl;
if (tabControl != null)
{
int selectedIndex = tabControl.SelectedIndex;
if (selectedIndex == 1)
{
SceneInScenesList.DataSource = scenes;
SceneInScenesList.DisplayMember = "Title";
Application.DoEvents();
int picked = SceneInScenesList.SelectedIndex;
SceneHint.Text = scenes[picked].Hint;
Application.DoEvents();
}
// Perform your desired actions based on the selected index.
// MessageBox.Show($"Selected tab index: {selectedIndex}");
}
}
private void Button1_Click(object sender, EventArgs e)
{
}
private void TextBox1_TextChanged(object sender, EventArgs e)
{
}
private void Label1_Click(object sender, EventArgs e)
{
}
private void MovieHintText_TextChanged(object sender, EventArgs e)
{
}
private void Label2_Click(object sender, EventArgs e)
{
}
private async void Button1_Click_1(object sender, EventArgs e)
{
MovieText.Text = gptModel + " awaiting reply...\r\n \r\n" + MovieHintText.Text;
string reply = await doMakeMovieText(MovieHintText.Text);
MovieText.Text = reply;
myMovie.movieText = reply;
myMovie.myNoteTextList.Add(new NotesMovieText(MovieText.Text, "", "-Base-"));
NotesList.DataSource = myMovie.myNoteTextList;
NotesList.DisplayMember = "myLabel";
Application.DoEvents();
}
private void Button3_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Label3_Click(object sender, EventArgs e)
{
}
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
MovieObj movie = new MovieObj();
MovieHintText.Text = movie.movieHintText;
}
private void SelectGPT35_CheckedChanged(object sender, EventArgs e)
{
if (SelectGPT35.Checked)
{
gptModel = "gpt-3.5-turbo";
SelectGPT4.Checked = false;
}
}
private void SelectGPT4_CheckedChanged(object sender, EventArgs e)
{
if (SelectGPT4.Checked)
{
gptModel = "gpt-4";
SelectGPT35.Checked = false;
}
}
private string makePrototypeMovieHint()
{
string hint = @"a 19 year old man <Robert> meets a 39 year old married woman <Beth>, and they both fall in love. A passionate affair ensues. <Beth> is married to <Oscar> a successful but cold and harsh 55 year old lawyer. <Sally> the 12 year old daughter of <Beth> and <Oscar> knows about <Beth>'s affair with <Robert> and pleads with <Beth> to end it. <Sally> warns <Beth> that <Oscar> is dangerous. The affair ends tragically when <Oscar> kills <Robert> and <Beth>. As a prominent citizen and using his skills as a lawyer, <Oscar> is not suspected by the police and he gets away with the crime. But <Sally> knows that he did it, and torments him for the rest of his life including on his death bed 20 years later. ";
return hint;
}
private async void button5_Click(object sender, EventArgs e)
{
doMakeScenesFromMovieText();
}
private void SceneInScenesList_SelectedIndexChanged(object sender, EventArgs e)
{
int picked = SceneInScenesList.SelectedIndex;
SceneHint.Text = scenes[picked].Hint;
Application.DoEvents();
}
private void SceneHint_TextChanged(object sender, EventArgs e)
{
}
private async void button6_Click(object sender, EventArgs e)
{
doMakeSceneText();
}
private async void button7_Click(object sender, EventArgs e)
{
string reply;
if (myMovie.movieText.Length > 200)
{
MovieTitle.Text = "making title from long...";
reply = await MyGPT.getTitle(api, myMovie.movieText, gptModel, this);
reply = "from long: " + reply;
}
else
{
MovieTitle.Text = "making title from hint...";
reply = await MyGPT.getTitle(api, myMovie.movieHintText, gptModel, this);
reply = "from hint: " + reply;
}
MovieTitle.Text = reply;
}
private async void button5_Click_1(object sender, EventArgs e)
{
doMakeBeatSheet();
}
private async void button5_Click_2(object sender, EventArgs e)
{
doWriteSceneScript();
}
private void SceneText_TextChanged(object sender, EventArgs e)
{
}
private void GPTError_Click(object sender, EventArgs e)
{
}
private void ErrorMessage_Click(object sender, EventArgs e)
{
}
public void updateGPTErrorMsg(string errorMsg,string exMessage)
{
ErrorMessage.Text = errorMsg;
if ( errorMsg.Length > 0)
{
ErrorLogBox.Text += exMessage + "\r\n";
}
Application.DoEvents();
}
private async void button5_Click_3(object sender, EventArgs e)
{
if (NotesForMovieText.Text.Length > 20)
{
string originalMovieText = myMovie.movieText;
string originalNote = NotesForMovieText.Text;
int sourceIndex = NotesList.SelectedIndex;
MovieText.Text = gptModel + " applying Notes to Text....\r\n \r\n" + MovieText.Text;
string response = await MyGPT.NotesForMovieText(api, gptModel, MovieText.Text, NotesForMovieText.Text, this);
MovieText.Text = response;
myMovie.movieText = response;
NotesTextKount += 1;
myMovie.myNoteTextList.Add(new NotesMovieText(myMovie.movieText, NotesForMovieText.Text, Utils.rightOfArrow(myMovie.myNoteTextList[sourceIndex].myLabel) + " -> Note #" + NotesTextKount.ToString()));
NotesList.DataSource = null;
NotesList.DisplayMember = null;
NotesList.DataSource = myMovie.myNoteTextList;
NotesList.DisplayMember = "myLabel";
NotesList.SelectedIndex = NotesTextKount;
Application.DoEvents();
}
else
{
MessageBox.Show("Not Enough Text Notes. Need at least 20 characters ");
}
}
private void NotesList_SelectedIndexChanged(object sender, EventArgs e)
{
if (NotesList.SelectedIndex >= 0 && NotesList.SelectedIndex <= myMovie.myNoteTextList.Count)
{
MovieText.Text = myMovie.myNoteTextList[NotesList.SelectedIndex].myMovieText;
NotesForMovieText.Text = myMovie.myNoteTextList[NotesList.SelectedIndex].myNote;
}
}
private void SentencesInSceneHint_ValueChanged(object sender, EventArgs e)
{
}
private void button5_Click_4(object sender, EventArgs e)
{
Font boldFont = new Font(BoldBox.Font, FontStyle.Bold);
Font regularFont = new Font(BoldBox.Font, FontStyle.Regular);
BoldBox.Focus();
BoldBox.AppendText("123 456 789");
BoldBox.Select(0, 11);
BoldBox.SelectionFont = boldFont;
BoldBox.Text += "\r\nabc def ghi";
}
public async Task<string> doMakeMovieText(string input)
{
string reply = await MyGPT.makeMovieText(api, input, gptModel, this);
return reply.ToString();
}
public async void doMakeScenesFromMovieText()
{
List<List<string>> ListofLists = new List<List<string>>();
if (MovieText.Text.Length < 200)
{
MessageBox.Show("Not Enough Movie Text. Need at least 50 characters ");
}
else
{
SceneDescriptions.Clear();
SceneDescriptions.Text = Utils.makePendingMessage(gptModel);
bool looper = true;
int errorKount = 0;
string jsonString = "";
string originalJSONString = "";
jsonString = await MyGPT.makeScenesFromMovieText(api, MovieText.Text, gptModel, (int)SceneCount.Value, (int)TokensInSceneHint.Value, GPTError.Text, this);
originalJSONString = jsonString;
while (looper == true)
{
try
{
ListofLists = JsonConvert.DeserializeObject<List<List<string>>>(jsonString);
SceneDescriptions.Text = jsonString;
looper = false;
}
catch (Exception ex)
{
if (errorKount == 0)
{
errorKount += 1;
jsonString = Utils.JSONFixer(originalJSONString);
Utils.nop();
looper = true;
}
else if (errorKount > 5)
{
Application.Exit();
}
else
{
errorKount += 1;
SceneDescriptions.Text = "error - trying to repair JSON. kount = " + errorKount.ToString() + "\r\n" + originalJSONString;
jsonString = await MyGPT.fixJSON(api, originalJSONString, gptModel, this);
looper = true;
}
}
}
scenes = new List<SceneObj>();
foreach (List<string> myScene in ListofLists)
{
SceneObj scene = new SceneObj();
string myTitle = myScene[0];
string Hint = myScene[1];
scene.Title = myTitle;
scene.Hint = Hint;
scenes.Add(scene);
}
ScenesList.DataSource = scenes;
ScenesList.DisplayMember = "Title";
}
}
public async void doMakeSceneText()
{
SceneText.Text = SceneHint.Text + "\r\n \r\n " + gptModel + " awaiting reply...";
string reply = await MyGPT.makeSceneText(api, gptModel, myMovie, scenes, SceneInScenesList.SelectedIndex + 1, this);
SceneText.Text = reply;
scenes[SceneInScenesList.SelectedIndex].NarrativeText = reply;
}
public async void doMakeBeatSheet()
{
if (SceneText.Text.Length > 50)
{
BeatSheetRichTextbox.Text = "making beat sheet from scene descriptiom.... ";
BeatSheetRichTextbox.Text = await MyGPT.makeBeatSheet(api, myMovie, SceneText.Text, gptModel, this);
scenes[SceneInScenesList.SelectedIndex].BeatSheetText = BeatSheetRichTextbox.Text;
}
else
{
MessageBox.Show("Not Enough Scene Text. Need at least 50 characters ");
}
}
public async void doWriteSceneScript()
{
if (BeatSheetRichTextbox.Text.Length > 50)
{
SceneScriptRichTextbox.Text = gptModel + " working on scene script....";
SceneScriptRichTextbox.Text = await MyGPT.makeSceneScript(api, myMovie, BeatSheetRichTextbox.Text, SceneText.Text, gptModel, this);
}
else
{
MessageBox.Show("Not Enough Beat Sheet. Need at least 50 characters ");
}
}
private async void button8_Click(object sender, EventArgs e)
{
// write a whole movie script from a movie text
Font boldFont = new Font(FullMovieScript.Font, FontStyle.Bold);
Font regularFont = new Font(FullMovieScript.Font, FontStyle.Regular);
if (scenes == null || scenes.Count == 0)
{
MessageBox.Show("Scenes not yet made ");
return;
}
string movieTitle = await MyGPT.getTitle(api, myMovie.movieText, gptModel, this);
int sceneKount = 0;
FullMovieScript.Font = boldFont;
FullMovieScript.Text = "";
FullMovieScript.Text = movieTitle + "\r\n\r\n";
FullMovieScript.Font = regularFont;
string mySceneText;
string myBeatSheetText;
string mySceneScriptText;
foreach (SceneObj theScene in scenes)
{
sceneKount += 1;
mySceneText = await MyGPT.makeSceneText(api, gptModel, myMovie, scenes, sceneKount, this);
SceneText.Text = mySceneText;
myBeatSheetText = await MyGPT.makeBeatSheet(api, myMovie, SceneText.Text, gptModel, this);
BeatSheetRichTextbox.Text = myBeatSheetText;
scenes[sceneKount -1].BeatSheetText = myBeatSheetText;
mySceneScriptText = await MyGPT.makeSceneScript(api, myMovie, myBeatSheetText, mySceneText, gptModel, this);
SceneScriptRichTextbox.Text = mySceneScriptText;
scenes[sceneKount - 1].SceneScript = mySceneScriptText;
FullMovieScript.Font = boldFont;
FullMovieScript.Text += $"Scene #{sceneKount} - {scenes[sceneKount - 1].Title}" + "\r\n\r\n";
FullMovieScript.Font = regularFont;
FullMovieScript.Text += mySceneScriptText + "\r\n\r\n";
}
return;
}
}
}