This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.py
2049 lines (1656 loc) · 83.8 KB
/
GUI.py
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
#version=4.0
#Implementing a version update system, instead of checking if file length is different.
import os
global thisdir
import requests
import re
import sys
import csv
import PIL.Image
#This will replace wget
def wget(URL,name):
response = requests.get(URL)
with open(f"{name}", 'wb') as file:
file.write(response.content)
global onefile_dir
thisdir = os.getcwd()
onefile_dir = thisdir
global ffmpeg_command
ffmpeg_command = 'ffmpeg'
homedir = os.path.expanduser(r"~")
if len(sys.argv) > 1:
if sys.argv[1] == '--compile-appimage':
GUI_List = []
with open('GUI.py', 'r') as f:
for line in f:
GUI_List.append(line)
if line == '#ffmpeg_command = ../ffmpeg\n':
line_index = GUI_List.index(line)
GUI_List[line_index] = 'ffmpeg_command = onefile_dir + "/ffmpeg"\n'
print(GUI_List[line_index])
if line == '#thisdir = f{homedir}/.Rife-Vulkan-GUI\n':
line_index = GUI_List.index(line)
GUI_List[line_index] ='thisdir = f\'{homedir}/.Rife-Vulkan-GUI\'\n'
print(GUI_List[line_index])
if line == '#onefile_dir = sys._MEIPASS\n':
line_index = GUI_List.index(line)
GUI_List[line_index] = 'onefile_dir = sys._MEIPASS\n'
print(GUI_List[line_index])
if os.path.isfile('GUIPortable.py') == False:
os.mknod('GUIPortable.py')
with open ('GUIPortable.py', 'w') as f:
for i in GUI_List:
f.write(i)
print('Completed')
exit()
#do not edit these lines.
#thisdir = f{homedir}/.Rife-Vulkan-GUI
#onefile_dir = sys._MEIPASS
#ffmpeg_command = ../ffmpeg
#you can edit from down here on
if os.path.exists(f'{homedir}/.Rife-Vulkan-GUI') == False:
os.mkdir(f'{homedir}/.Rife-Vulkan-GUI')
if os.path.exists(f"{thisdir}/files/") == False:
os.mkdir(f"{thisdir}/files/")
if(os.path.isfile(thisdir+"/files/settings.txt")) == False and ffmpeg_command == 'ffmpeg':
os.chdir(f"{thisdir}/files")
os.system(f'curl -O "https://bootstrap.pypa.io/get-pip.py" > get-pip.py')
os.system(f'python3 -m pip install requests')
os.chdir(f"{thisdir}")
os.system(f'python3 files/get-pip.py install')
os.system(f'python3 -m pip install opencv-python')
os.system(f'python3 -m pip install tk')
os.system(f'python3 -m pip install psutil')
os.system(f'rm files/get-pip.py')
import getpass
from pathlib import Path
import pathlib
import os
import glob
from tkinter.ttk import Progressbar
import sys
import os.path
from tkinter import *
from tkinter import filedialog
from multiprocessing import Queue, Process
import subprocess
from subprocess import Popen, PIPE
from time import sleep
from threading import *
from tkinter import ttk
import ntpath
from sys import exit
import glob
import os.path
import cv2
from tkinter import *
import psutil
from zipfile import ZipFile
from PIL import ImageTk
import time
# These change the settings file
def write_to_settings_file(description, option):
with open(f'{thisdir}/files/settings.txt', 'a') as f:
f.write(description + ","+option + "\n")
def read_settings():
global settings_dict
settings_dict = {}
with open(f'{thisdir}/files/settings.txt', 'r') as f:
f = csv.reader(f)
for row in f:
try:
settings_dict[row[0]] = row[1]
except:
pass
try:
global Rife_Option
Rife_Option = settings_dict['Rife_Option']
global Interpolation_Option
Interpolation_Option = settings_dict['Interpolation_Option']
global Repository
Repository = settings_dict['Repository']
global Image_Type
Image_Type = settings_dict['Image_Type']
global IsAnime
IsAnime = settings_dict['IsAnime']
global rifeversion
rifeversion = settings_dict['rifeversion']
global esrganversion
esrganversion = settings_dict['esrganversion']
global videoQuality
videoQuality = settings_dict['videoQuality']
global Theme
Theme = settings_dict['Theme']
global OutputDir
OutputDir = settings_dict['OutputDir']
global GPUUsage
GPUUsage = settings_dict['GPUUsage']
global RenderDevice
RenderDevice = settings_dict['RenderDevice']
global RenderDir
RenderDir = settings_dict['RenderDir']
global ExtractionImageType
ExtractionImageType=settings_dict['ExtractionImageType']
global SceneChangeDetection
SceneChangeDetection=settings_dict['SceneChangeDetection']
except:
os.system(f'rm -rf "{thisdir}/files/settings.txt"')
os.mknod(f'{thisdir}/files/settings.txt')
write_to_settings_file("Image_Type", "png")
write_to_settings_file("IsAnime", "False")
write_to_settings_file("Repository", "stable")
write_to_settings_file("rifeversion", "20221029")
write_to_settings_file("esrganversion", "0.2.0")
write_to_settings_file("videoQuality", "14")
write_to_settings_file("Theme", "Dark")
write_to_settings_file("OutputDir", f"{homedir}")
write_to_settings_file("Interpolation_Option", f"2X")
write_to_settings_file("Rife_Option" ,'2.3')
write_to_settings_file("GPUUsage" ,'Default')
write_to_settings_file("RenderDevice" ,'GPU')
write_to_settings_file("RenderDir" ,f"{thisdir}")
write_to_settings_file("ExtractionImageType" ,"jpg")
write_to_settings_file('SceneChangeDetection','0.3')
settings_dict = {}
with open(f'{thisdir}/files/settings.txt', 'r') as f:
f = csv.reader(f)
for row in f:
settings_dict[row[0]] = row[1]
Rife_Option = settings_dict['Rife_Option']
Interpolation_Option = settings_dict['Interpolation_Option']
Repository = settings_dict['Repository']
Image_Type = settings_dict['Image_Type']
IsAnime = settings_dict['IsAnime']
rifeversion = settings_dict['rifeversion']
esrganversion = settings_dict['esrganversion']
videoQuality = settings_dict['videoQuality']
Theme = settings_dict['Theme']
OutputDir = settings_dict['OutputDir']
GPUUsage = settings_dict['GPUUsage']
RenderDevice = settings_dict['RenderDevice']
RenderDir = settings_dict['RenderDir']
def write_defaults():
write_to_settings_file("Image_Type", "png")
write_to_settings_file("IsAnime", "False")
write_to_settings_file("Repository", "stable")
write_to_settings_file("rifeversion", "20221029")
write_to_settings_file("esrganversion", "0.2.0")
write_to_settings_file("videoQuality", "14")
write_to_settings_file("Theme", "Dark")
write_to_settings_file("OutputDir", f"{homedir}")
write_to_settings_file("Interpolation_Option", f"2X")
write_to_settings_file("Rife_Option" ,'2.3')
write_to_settings_file("GPUUsage" ,'Default')
write_to_settings_file("RenderDevice" ,'GPU')
write_to_settings_file("RenderDir" ,f"{thisdir}")
write_to_settings_file("ExtractionImageType" ,"jpg")
write_to_settings_file('SceneChangeDetection','0.3')
try:
read_settings()
except:
pass
if os.path.isfile(f'{thisdir}/files/settings.txt') == False:
os.mknod(f'{thisdir}/files/settings.txt')
write_defaults()
def write_temp(): # im doing this because i am lazy
change_setting("Interpolation_Option", f"2X")
change_setting("Rife_Option", f"2.3")
change_setting("IsAnime", "False")
read_settings()
def change_setting(setting,svalue):
original_settings = {}
with open(f'{thisdir}/files/settings.txt', 'r') as f:
f = csv.reader(f)
for row in f:
original_settings[row[0]] = row[1]
original_settings[setting] = svalue
os.system(f'rm -rf "{thisdir}/files/settings.txt" && touch "{thisdir}/files/settings.txt"')
for key,value in original_settings.items():
with open(f'{thisdir}/files/settings.txt', 'a') as f:
f.write(key + ',' + value+'\n')
read_settings()
write_temp()
def check_output_dir():
if os.path.exists(f'{OutputDir}') == False:
change_setting('OutputDir', f'{homedir}')
if os.path.exists(f'{RenderDir}') == False:
change_setting('RenderDir', f'{thisdir}')
check_output_dir()
global realsr_model
realsr_model = '-n realesrgan-x4plus -s 4'
os.system(f'chmod +x "{thisdir}/rife-vulkan-models/rife-ncnn-vulkan"')
def check_theme():
# This code reads the theme file and stores its data in a theme variable
return Theme
videopath = ""
global main_window
main_window = Tk()
tabControl = ttk.Notebook(main_window)
if check_theme() == "Light":
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
tab3 = ttk.Frame(tabControl)
tab4 = ttk.Frame(tabControl)
s = ttk.Style()
# Create style used by default for all Frames
s.configure('TFrame', background='White')
# Create style for the first frame
s.configure('Frame1.TFrame', background='White', foreground='Black')
if check_theme() == "Dark":
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
tab3 = ttk.Frame(tabControl)
tab4 = ttk.Frame(tabControl)
s = ttk.Style()
# Create style used by default for all Frames
s.configure('TFrame', background='#4C4E52',foreground='#4C4E52')
# Create style for the first frame
s.configure('Frame1.TFrame', background='red')
#Create tabs
tabControl.add(tab1, text='Rife')
tabControl.add(tab2, text='Real-ESRGAN')
tabControl.add(tab3, text='Preview')
tabControl.add(tab4, text='Settings')
tabControl.grid(row=0,column=0)
def grayout_tabs(mode):
if mode == 'rife':
tabControl.tab(tab2, state='disabled')
if mode == 'realsr':
tabControl.tab(tab1, state='disabled')
tabControl.tab(tab4, state='disabled')
def enable_tabs():
tabControl.tab(tab1, state='normal')
tabControl.tab(tab2, state='normal')
tabControl.tab(tab4, state='normal')
if check_theme() == "Light":
main_window.config(bg="white")
fg="black"
bg="White"
bg_button="white"
if check_theme() == "Dark":
main_window.config(bg="#4C4E52")
fg="white"
bg_button="#4C4E52"
def latest_ESRGAN():
# this code gets the latest versaion of rife vulkan
latest = requests.get('https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan/releases/latest')
latest = latest.url
latest = re.findall(r'v[\d].[\d].[\d]*$', latest)
latest = latest[0]
current = esrganversion
return(latest,current)
# this checks for updates
# it makes a temp folder, and gets the latest GUI.py from github
# It compares the files, and if the files are different, replaces the old GUI.py with the one from github
# Ive changed it to the Stable branch which created, this helps prevent unintended bugs from getting in the updates
def check_for_updates():
is_updated = 0
os.system(f'mkdir -p "{thisdir}/temp/"')
os.chdir(f"{thisdir}/temp/")
if repo =="Stable":
wget('https://raw.githubusercontent.com/TNTwise/Rife-Vulkan-GUI-Linux/Stable/GUI.py', 'GUI.py')
wget('https://raw.githubusercontent.com/TNTwise/Rife-Vulkan-GUI-Linux/Stable/start.py', 'start.py')
wget('https://raw.githubusercontent.com/TNTwise/Rife-Vulkan-GUI-Linux/Stable/Start', 'Start')
if repo =="Testing":
wget('https://raw.githubusercontent.com/TNTwise/Rife-Vulkan-GUI-Linux/main/GUI.py', 'GUI.py')
wget('https://raw.githubusercontent.com/TNTwise/Rife-Vulkan-GUI-Linux/main/start.py', 'start.py')
wget('https://raw.githubusercontent.com/TNTwise/Rife-Vulkan-GUI-Linux/main/Start', 'Start')
os.chdir(f"{thisdir}")
file1 = open(f"{thisdir}/temp/GUI.py")
file2 = open(f"{thisdir}/GUI.py")
file1_lines = file1.readlines()
file2_lines = file2.readlines()
version = latest_rife() # calls latest function which gets the latest version release of rife and returns the latest and the current, if the version file doesnt exist, it updates and creates the file
latest_ver = version[0]
current = version[1]
if len(file1_lines) != len(file2_lines):
is_updated = 1
os.system(f'rm -rf "{thisdir}/GUI.py"')
os.system(f'mv "{thisdir}/temp/GUI.py" "{thisdir}/"')
os.system(f'rm -rf "{thisdir}/start.py"')
os.system(f'mv "{thisdir}/temp/start.py" "{thisdir}/files/"')
os.system(f'rm -rf "{thisdir}/Start"')
os.system(f'mv "{thisdir}/temp/Start" "{thisdir}/"')
os.system(f'chmod +x "{thisdir}/Start"')
os.system(f'rm -rf "{thisdir}/temp/"')
os.system(f'rm -rf "{thisdir}/temp/"')
if latest_ver > current:
is_updated = 1
os.chdir(f"{thisdir}/files/")
wget(f"https://github.com/nihui/rife-ncnn-vulkan/releases/download/{latest_ver}/rife-ncnn-vulkan-{latest_ver}-ubuntu.zip", f"rife-ncnn-vulkan-{latest_ver}-ubuntu.zip")
with ZipFile(f'rife-ncnn-vulkan-{latest_ver}-ubuntu.zip','r') as f:
f.extractall()
os.chdir(f"{thisdir}")
os.system(f'rm -rf "{thisdir}/files/rife-ncnn-vulkan"')
os.system(f'mv "{thisdir}/rife-ncnn-vulkan-{latest_ver}-ubuntu" "{thisdir}/files/"')
os.system(f'mv "{thisdir}/files/rife-ncnn-vulkan-{latest_ver}-ubuntu/"* "{thisdir}/rife-vulkan-models/"')
os.system(f'chmod +x "{thisdir}/files/rife-ncnn-vulkan"')
change_setting('rifeversion',f'{latest_ver}')
os.system(f'rm -rf "{thisdir}/files/rife-ncnn-vulkan-{latest_ver}-ubuntu.zip"')
os.system(f'rm -rf "{thisdir}/files/rife-ncnn-vulkan-{latest_ver}-ubuntu"')
if is_updated == 1:
return 1
else:
return
# set theme on launch, this sets bg and bg_background, this is set throughout the entire script
if check_theme() == "Light":
main_window.config(bg="white")
fg="black"
bg="white"
bg_button="white"
if check_theme() == "Dark":
main_window.config(bg="#4C4E52")
fg="white"
bg="#4C4E52"
bg_button="#4C4E52"
cmd = 'ls -l'
# use threading
# insert elements by their
# index and names.
# Insert settings menu here
def settings_window():
button_select_default_output = Button(tab4,
text = "Select default output folder",
command = sel_default_output_folder, bg=bg_button,fg=fg)
# just writes 'stable' to file repository to be able to change where the program is taken from
current_default_output_folder = OutputDir
#displays current default output folder
global default_output_label
default_output_label = Label(tab4, text=current_default_output_folder,bg=bg,fg=fg, width=25, anchor="w")
# creates theme button and calls check_theme which returns the theme that is currently on
global repo
repo = Repository
if repo == "stable": # capitolizes repo first char
repo = "Stable"
if repo == "testing":
repo = "Testing"
global theme_button
theme = check_theme()
if theme == "Light":
theme_button = Button(tab4,text="Light",command=darkTheme,bg="white",fg=fg)
if theme == "Dark":
theme_button = Button(tab4,text="Dark",command=lightTheme,bg=bg,fg=fg)
theme_label = Label(tab4,text=" Theme: ",bg=bg,fg=fg)
spacer_label = Label(tab4,text=" ",bg=bg) # This spaces the middle
spacer_label1 = Label(tab4,text=" ",bg=bg) # this spaces the end
spacer_label2 = Label(tab4,text="",bg=bg) # this is at the start of the gui
global default_render_label
default_render_label = Label(tab4,text=RenderDir,bg=bg,fg=fg,width=25,anchor='w')
default_render_label.grid(column=6,row=1)
global check_updates_button
check_updates_button = Button(tab4,text="Check For Updates", command=start_update_check_thread, bg=bg,fg=fg)
global update_spacer_label
update_spacer_label = Label(tab4,text = " ", bg=bg)
button_select_default_render = Button(tab4,
text = "Select default render folder",
command = sel_default_render_folder, bg=bg_button,fg=fg).grid(column=6, row=0)
def video_image_dropdown():
update_branch_label = Label(tab4,text="Render Image Type: ",bg=bg,fg=fg)
update_branch_label.grid(column=1,row=5)
variable = StringVar(tab4)
repo_options = ['webp (smaller size, lossless)', 'png (lossless)', 'jpg (lossy)']
variable.set(Image_Type)
opt = OptionMenu(tab4, variable, *repo_options)
opt.config(width=4,font=('Ariel', '12'))
opt.config(bg=bg)
opt.config(fg=fg)
opt.config(anchor="w")
opt.grid(column=1,row=6)
def callback(*args):
if variable.get() == 'webp (smaller size, lossless)':
change_setting('Image_Type', 'webp')
global Image_Type
Image_Type = 'webp'
read_settings()
if variable.get() == 'png (lossless)':
Image_Type = 'png'
change_setting('Image_Type', 'png')
read_settings()
if variable.get() == 'jpg (lossy)':
change_setting('Image_Type', 'jpg')
Image_Type = 'jpg'
read_settings()
variable.trace("w", callback)
def gpu_usage_dropdown():
update_branch_label = Label(tab4,text="System Load:",bg=bg,fg=fg)
update_branch_label.grid(column=4,row=5)
variable = StringVar(tab4)
repo_options = ['Default', 'Low', 'High', 'Very High', 'Custom']
if GPUUsage == 'Default' or GPUUsage == 'Low' or GPUUsage == 'High' or GPUUsage == 'Very High':
variable.set(GPUUsage)
else:
variable.set('Custom')
global save_button
global custom_box1
custom_box1 = Text(tab4,width=10,height=1)
custom_box1.insert("end-1c", GPUUsage)
custom_box1.grid(row=7,column=4)
save_button = Button(tab4,width=10,height=1,text='Save',fg=fg,bg=bg,command=lambda: change_setting("GPUUsage", custom_box1.get('1.0', 'end-1c')))
save_button.grid(row=8,column=4)
opt = OptionMenu(tab4, variable, *repo_options)
opt.config(width=8,font=('Ariel', '12'))
opt.config(bg=bg)
opt.config(fg=fg)
opt.config(anchor="w")
opt.grid(column=4,row=6)
def callback(*args):
if variable.get() != 'Custom':
remove_custom()
change_setting("GPUUsage", variable.get())
read_settings()
else:
if GPUUsage == 'Default' or GPUUsage == 'Low' or GPUUsage == 'High' or GPUUsage == 'Very High':
change_setting("GPUUsage", "10")
custom_box1 = Text(tab4,width=10,height=1)
custom_box1.insert("end-1c", GPUUsage)
custom_box1.grid(row=7,column=4)
save_button = Button(tab4,width=10,height=1,text='Save',fg=fg,bg=bg,command=lambda: change_setting("GPUUsage", custom_box1.get('1.0', 'end-1c')))
save_button.grid(row=8,column=4)
variable.trace("w", callback)
def after_interpolation():
update_branch_label = Label(tab4,text="After interpolation: ",bg=bg,fg=fg)
update_branch_label.grid(column=4,row=8)
variable = StringVar(tab4)
repo_options = ['Nothing', 'Shutdown']
variable.set('Nothing')
opt = OptionMenu(tab4, variable, *repo_options)
opt.config(width=9,font=('Ariel', '12'))
opt.config(bg=bg)
opt.config(fg=fg)
opt.config(anchor="w")
opt.grid(column=4,row=9)
def callback(*args):
global after_interpolation_var
after_interpolation_var = variable.get()
variable.trace("w", callback)
after_interpolation()
def remove_custom():
try:
custom_box1.destroy()
save_button.destroy()
except:
pass
def RenderDeviceDropDown():
update_branch_label = Label(tab4,text="Render Device:",bg=bg,fg=fg)
update_branch_label.grid(column=6,row=5)
variable = StringVar(tab4)
repo_options = ['CPU', 'GPU', 'Dual GPU', 'CPU + GPU']
if RenderDevice != 'CPU + GPU':
variable.set(RenderDevice)
else:
variable.set('CPU + GPU')
opt = OptionMenu(tab4, variable, *repo_options)
opt.config(width=9,font=('Ariel', '12'))
opt.config(bg=bg)
opt.config(fg=fg)
opt.config(anchor="w")
opt.grid(column=6,row=6)
def callback(*args):
if variable.get() != 'CPU + GPU':
change_setting("RenderDevice", variable.get())
else:
change_setting("RenderDevice", 'CPU + GPU')
variable.trace("w", callback)
RenderDeviceDropDown()
gpu_usage_dropdown()
video_image_dropdown()
#show_dropdown()
def video_quality_drop_down():
vid_quality_label = Label(tab4,text="Video quality:", bg=bg,fg=fg).grid(column=1,row=2)
vidQuality = videoQuality
if vidQuality == "22":
vidQuality1 = "Low"
if vidQuality == "18":
vidQuality1 = "Medium"
if vidQuality == "14":
vidQuality1 = "High"
if vidQuality == "7":
vidQuality1 = "Lossless"
variable = StringVar(tab4)
repo_options = ['Lossless','High', 'Medium', 'Low']
variable.set(vidQuality1)
opt = OptionMenu(tab4, variable, *repo_options)
opt.config(width=9,font=('Ariel', '12'))
opt.config(bg=bg)
opt.config(fg=fg)
opt.grid(column=1,row=3)
def callback(*args):
# Converts these to cfv format
if variable.get() == "Low":
change_setting('videoQuality', '22')
if variable.get() == "Medium":
change_setting('videoQuality', '18')
if variable.get() == "High":
change_setting('videoQuality', '14')
if variable.get() == "Lossless":
change_setting('videoQuality', '7')
variable.trace("w", callback)
video_quality_drop_down()
class advancedOptions():
def __init__(self):
self.advanced_settings_window = Tk()
try:
self.advanced_settings_window.iconphoto(False, PhotoImage(file=f'{onefile_dir}/icons/icon-256x256.png'))
except:
pass
self.advanced_settings_window.config(bg=bg)
self.layout()
self.advanced_settings_window.geometry("600x400")
self.advanced_settings_window.title('Advanced Settings')
self.advanced_settings_window.resizable(False, False)
self.advanced_settings_window.mainloop()
def layout(self):
Label(self.advanced_settings_window, text='Extraction Image Type:',font=('Ariel', '12'),bg=bg,fg=fg).grid(column=1,row=0)
Label(self.advanced_settings_window, text=' Scene change detection sensitivity:',font=('Ariel', '12'),bg=bg,fg=fg).grid(column=2,row=0)
def extraction_image_drop_down():
extraction_image_variable = StringVar(self.advanced_settings_window)
extraction_image_options = ['JPG','PNG']
extraction_image_variable.set(ExtractionImageType.upper())
extraction_imageDropDown = OptionMenu(self.advanced_settings_window, extraction_image_variable, *extraction_image_options)
extraction_imageDropDown.config(width=4,font=('Ariel', '12'))
extraction_imageDropDown.config(bg=bg)
extraction_imageDropDown.config(fg=fg)
extraction_imageDropDown.grid(column=1,row=1)
def callback(*args):
change_setting('ExtractionImageType',(extraction_image_variable.get().lower()))
extraction_image_variable.trace("w", callback)
extraction_image_drop_down()
def transition_detection_drop_down():
transition_detection_variable = StringVar(self.advanced_settings_window)
extraction_image_options = ['Off','Low','Medium','High']
if SceneChangeDetection == 'Off':
transition_detection_variable.set('Off')
if SceneChangeDetection == '0.2':
transition_detection_variable.set('High')
if SceneChangeDetection == '0.3':
transition_detection_variable.set('Medium')
if SceneChangeDetection == '0.4':
transition_detection_variable.set('Low')
else:
write_defaults()
transition_detection_drop_down = OptionMenu(self.advanced_settings_window, transition_detection_variable, *extraction_image_options)
transition_detection_drop_down.config(width=6,font=('Ariel', '12'))
transition_detection_drop_down.config(bg=bg)
transition_detection_drop_down.config(fg=fg)
transition_detection_drop_down.grid(column=2,row=1)
def callback(*args):
if transition_detection_variable.get() == 'Off':
change_setting('SceneChangeDetection','Off')
if transition_detection_variable.get() == 'High':
change_setting('SceneChangeDetection','0.2')
if transition_detection_variable.get() == 'Medium':
change_setting('SceneChangeDetection','0.3')
if transition_detection_variable.get() == 'Low':
change_setting('SceneChangeDetection','0.4')
transition_detection_variable.trace("w", callback)
transition_detection_drop_down()
advanced_options_button = Button(tab4,width=15,height=1,text='Advanced Options',bg=bg,fg=fg,command=advancedOptions,font=('Ariel', '12'))
# lays out the menu
spacer_label2.grid(column=0,row=0)
spacer_label2.config(padx=30)
button_select_default_output.grid(column=1, row=0)
default_output_label.grid(column=1, row=1)
spacer_label.grid(column=2,row=0)
theme_label.grid(column=4,row=0)
theme_button.grid(column=4, row=1)
spacer_label1.grid(column=5,row=0)
#check_updates_button.grid(column=6,row=3)
update_spacer_label.grid(column=6,row=2)
#change_repo_dropdown.grid(column=5,row=2)
Label(tab4,text='',bg=bg,fg=fg,font=('Ariel', '16')).grid(column=1,row=8)
advanced_options_button.grid(column=1,row=9)
# this will show if updates exist
def start_update_check():
global update_check_label
if check_for_updates() == 1:
update_check_label = Label(tab4,text="Updated, restart to apply.",bg=bg,fg=fg)
check_updates_button = Button(tab4,text="Check For Updates", command=start_update_check_thread, bg=bg,fg=fg).grid(column=6,row=3)
restart_window("Updated, re-launch the program to apply.")
else:
update_check_label = Label(tab4,text="No Updates",bg=bg,fg=fg)
check_updates_button = Button(tab4,text="Check For Updates", command=start_update_check_thread, bg=bg,fg=fg).grid(column=6,row=3)
update_check_label.grid(column=6,row=5)
# restarts the program
def restart():
os.system("pkill -f GUI.py && python3 start.py")
def restart_thread():
t1 = Thread(target=restart_window)
t1.start()
def exit_thread():
# Call work function
t1 = Thread(target=exi11)
t1.start()
# restart window, this allows the program to restart after a application settings changes. call this with a message to confirm restart of program.
def restart_window(message):
restart_window = Tk()
centering_label = Label(restart_window, text=" ")
restart_label = Label(restart_window, text=message, justify=CENTER)
exit_button = Button(restart_window, text="Exit", command=exit_thread,justify=CENTER)
#restart_button = Button(restart_window, text="Restart", command=restart_thread,justify=CENTER)
# lays out restart window
centering_label.grid(column=0,row=0)
#restart_button.grid(column=0,row=1)
exit_button.grid(column=0,row=1)
restart_label.grid(column=0,row=2)
# sets window values
restart_window.title("")
restart_window.geometry("300x200")
restart_window.resizable(False, False)
restart_window.mainloop()
#This returns the settings for each gpu setting
def get_render_device(app):
if app != 'realsr':
if RenderDevice == 'GPU':
return ""
if RenderDevice == 'CPU':
return "-g -1"
if RenderDevice == 'Dual GPU':
return "-g 0,0,1"
if RenderDevice == 'CPU + GPU':
return '-g -1,0,0'
else:
return ""
def gpu_setting(app):
if GPUUsage == 'Default' or GPUUsage == 'Low' or GPUUsage == 'High' or GPUUsage == 'Very High':
pass
else:
l = (f'-j {GPUUsage}:{GPUUsage}:{GPUUsage}')
return l
if GPUUsage == 'Default' and RenderDevice == 'GPU' or RenderDevice == 'CPU':
return ""
if GPUUsage == 'High' and RenderDevice == 'GPU' or RenderDevice == 'CPU':
return "-j 3:7:3"
if GPUUsage == 'Very High' and RenderDevice == 'GPU' or RenderDevice == 'CPU':
return "-j 10:10:10"
if GPUUsage == 'Low' and RenderDevice == 'GPU' or RenderDevice == 'CPU':
return "-j 1:1:1"
if app != 'realsr':
if GPUUsage == 'Default' and RenderDevice == 'Dual GPU':
return "-j 1:2,2,2:2"
if GPUUsage == 'High' and RenderDevice != 'GPU' and RenderDevice == 'Dual GPU':
return "-j 5:5,5,5:5"
if GPUUsage == 'Very High' and RenderDevice != 'GPU' and RenderDevice == 'Dual GPU':
return "-j 10:10,10,10:10"
if GPUUsage == 'Low' and RenderDevice != 'GPU' and RenderDevice == 'Dual GPU':
return "-j 1:1,1,1:1"
if GPUUsage =='Default' and RenderDevice == 'CPU + GPU':
return '-j 2:4,2,1:4'
if GPUUsage =='Low' and RenderDevice == 'CPU + GPU':
return '-j 1:2,1,1:2'
if GPUUsage =='High' and RenderDevice == 'CPU + GPU':
return '-j 8:8,8,8:8'
if GPUUsage =='Very High' and RenderDevice == 'CPU + GPU':
return '-j 10:10,12,12:10'
else:
if GPUUsage == 'Default':
return "-j 1:2:2"
if GPUUsage == 'High':
return "-j 5:5:5"
if GPUUsage == 'Very High':
return "-j 10:10:10"
def latest_rife():
# this code gets the latest versaion of rife vulkan
latest = requests.get('https://github.com/nihui/rife-ncnn-vulkan/releases/latest/')
latest = latest.url
latest = re.findall(r'[\d]*$', latest)
latest = latest[0]
current = rifeversion
return(latest,current)
def preview_image():
i=1
g=1
dir_path = f'{RenderDir}/{filename}/output_frames/'
while i==1:
if os.path.exists(f'{RenderDir}/{filename}/output_frames/') == False:
label.destroy()
break
sleep(1)
files = os.listdir(dir_path)
files.sort()
try:
img = PIL.Image.open(f"{RenderDir}/{filename}/output_frames/{files[-1]}")
width, height = img.size
desired_width = 820
proportional_height = int((desired_width / float(width)) * height)
img = img.resize((desired_width, proportional_height), PIL.Image.LANCZOS)
photo = ImageTk.PhotoImage(img)
label = Label(tab3,image=photo,width=desired_width,height=proportional_height)
label.grid(column=1,row=0)
except:
pass
#switches theme for tkinter
def darkTheme():
change_setting('Theme', 'Dark')
global bg
global bg_button
global fg
bg="#4C4E52"
fg="white"
bg_button="#4C4E52"
restart_window("Changing theme requires restart.")
def lightTheme():
change_setting('Theme', 'Light')
global bg
global bg_button
global fg
bg="white"
bg_button="white"
fg="black"
restart_window("Changing theme requires restart.")
def sel_default_render_folder():
select_default_render_folder = filedialog.askdirectory(initialdir = fr"/",
title = "Select a Folder",)
if isinstance(select_default_render_folder, str) == True and len(select_default_render_folder) > 0:
change_setting('RenderDir', select_default_render_folder)
#displays current default output folder
default_render_label.destroy()
default_render_label_1 = Label(tab4, text=select_default_render_folder,bg=bg,fg=fg, width=25, anchor="w")
default_render_label_1.grid(column=6, row=1)
def sel_default_output_folder():
global select_default_output_folder
select_default_output_folder = filedialog.askdirectory(initialdir = fr"{homedir}",
title = "Select a Folder",)
if isinstance(select_default_output_folder, str) == True and len(select_default_output_folder) > 0:
change_setting('OutputDir', select_default_output_folder)
current_default_output_folder = OutputDir
#displays current default output folder
default_output_label.destroy()
default_output_label_1 = Label(tab4, text=current_default_output_folder,bg=bg,fg=fg, width=25, anchor="w")
default_output_label_1.grid(column=1, row=1)
'''def remove_processced_files(): #scraping this for now
def start():
i = 0
while i == 0:
frames_processced =len(list(Path(f'{RenderDir}/{filename}/output_frames/').glob('*')))
frames_to_remove = int(frames_processced/2) - 20
frame = str(frames_to_remove).zfill(8)
os.system(f'rm -rf "{RenderDir}/{filename}/input_frames/frame_{frame}.png"')
if os.path.exists(f'{RenderDir}/{filename}/input_frames/') == False:
break
Thread(target=start).start()'''
def show(program):
# These 2 variables are the defaults, will need to remove when make default selector.
if program == "rife":
rifever = ""
read_settings()
interpolation_option = settings_dict['Interpolation_Option']
rifever1 = Rife_Option
isAnime = IsAnime
if isAnime != "True":
if rifever1 == "Rife":
rifever = "-m rife"
if rifever1 == "HD":
rifever = "-m rife-HD"
if rifever1 == "UHD":
rifever = "-m rife-UHD"
if rifever1 == "2.0":
rifever = "-m rife-v2"
if rifever1 == "2.3":
rifever = "-m rife-v2.3"
if rifever1 == "3.0":
rifever = "-m rife-v3.0"
if rifever1 == "4.0":
rifever = "-m rife-v4"
if rifever1 == "2.4":
rifever = "-m rife-v2.4"
if rifever1 == "3.1":
rifever = "-m rife-v3.1"
if rifever1 == "4.6":
rifever = "-m rife-v4.6"
if rifever1 == "Anime":
rifever = "-m rife-anime"
if interpolation_option == "2X":
on_click(rifever)
if interpolation_option == "4X":
times4(rifever)
if interpolation_option == "8X":
times8(rifever)
else: