mirror of
https://github.com/deepfakes/faceswap
synced 2025-06-08 20:13:52 -04:00
* GUI version 3 (#411) GUI version 3.0a * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Add OriginalHighRes 128 update to gui branch (#421) * Required for Shaonlu mode (#416) Added two modes - Original and Shaonlu. The later requires this file to function. * model update (#417) New, functional Original 128 model * OriginalHighRes 128 model update (#418) Required for OriginalHighRes Model to function * Dev gui (#420) * reduce singletons * Fix tooltips and screen boundaries on popup * Remove dpi fix. Fix context filebrowsers * fix tools.py execution and context filebrowser bugs * Bugfixes (#422) * Bump matplotlib requirement. Fix polyfit. Fix TQDM on sort * Fixed memory usage at 6GB cards. (#423) - Switched default encoder to ORIGINAL - Fixed memory consumption. Tested with geforce gtx 9800 ti with 6Gb; batch_size 8 no OOM or memory warnings now. * Staging (#426) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Add DPI Scaling (#428) * Add dpi scaling * Hotfix for effmpeg. (#429) effmpeg fixed so it works both in cli and gui. Initial work done to add previewing feature to effmpeg (currently does nothing). Some small spacing changes in other files to improve PEP8 conformity. * PEP8 Linting (#430) * pep8 linting * Requirements version bump (#432) * altered trainer (#425) altered trainer to accommodate with model change * Update Model.py (#424) - Added saving state (currently only saved epoch number, to be extended in future) - Changed saving to ThreadPoolExecutor * Requirements version bump (#431) This bumps the versions of: scandir h5py Keras opencv-python to their latest vesions. Virtual Environment will need to be setup again to make use of these. * High DPI Fixes (#433) * dpi scaling * DPI Fixes * Fix and improve context manager. (#434) effmpeg tool: Context manager for GUI fixed. Context manager in general: Functionality extended to allow configuring the context with both: command -> action command -> variable (cli argument) -> action * Change epoch option to iterations * Change epochs to iterations
138 lines
4.8 KiB
Python
138 lines
4.8 KiB
Python
#!/usr/bin python3
|
|
""" The optional GUI for faceswap """
|
|
|
|
import os
|
|
import sys
|
|
import tkinter as tk
|
|
|
|
from tkinter import messagebox, ttk
|
|
|
|
from lib.gui import (CliOptions, CurrentSession, CommandNotebook, Config,
|
|
ConsoleOut, DisplayNotebook, Images, ProcessWrapper,
|
|
StatusBar)
|
|
|
|
|
|
class FaceswapGui(tk.Tk):
|
|
""" The Graphical User Interface """
|
|
|
|
def __init__(self, pathscript):
|
|
tk.Tk.__init__(self)
|
|
self.scaling_factor = self.get_scaling()
|
|
self.set_geometry()
|
|
|
|
pathcache = os.path.join(pathscript, "lib", "gui", ".cache")
|
|
self.images = Images(pathcache)
|
|
self.cliopts = CliOptions()
|
|
self.session = CurrentSession()
|
|
statusbar = StatusBar(self)
|
|
self.wrapper = ProcessWrapper(statusbar,
|
|
self.session,
|
|
pathscript,
|
|
self.cliopts)
|
|
|
|
self.images.delete_preview()
|
|
self.protocol("WM_DELETE_WINDOW", self.close_app)
|
|
|
|
def get_scaling(self):
|
|
""" Get the display DPI """
|
|
dpi = self.winfo_fpixels("1i")
|
|
return dpi / 72.0
|
|
|
|
def set_geometry(self):
|
|
""" Set GUI geometry """
|
|
self.tk.call("tk", "scaling", self.scaling_factor)
|
|
width = int(1200 * self.scaling_factor)
|
|
height = int(640 * self.scaling_factor)
|
|
self.geometry("{}x{}+80+80".format(str(width), str(height)))
|
|
|
|
def build_gui(self, debug_console):
|
|
""" Build the GUI """
|
|
self.title("Faceswap.py")
|
|
self.menu()
|
|
|
|
topcontainer, bottomcontainer = self.add_containers()
|
|
|
|
CommandNotebook(topcontainer,
|
|
self.cliopts,
|
|
self.wrapper.tk_vars,
|
|
self.scaling_factor)
|
|
DisplayNotebook(topcontainer,
|
|
self.session,
|
|
self.wrapper.tk_vars,
|
|
self.scaling_factor)
|
|
ConsoleOut(bottomcontainer, debug_console, self.wrapper.tk_vars)
|
|
|
|
def menu(self):
|
|
""" Menu bar for loading and saving configs """
|
|
menubar = tk.Menu(self)
|
|
filemenu = tk.Menu(menubar, tearoff=0)
|
|
|
|
config = Config(self.cliopts, self.wrapper.tk_vars)
|
|
|
|
filemenu.add_command(label="Load full config...",
|
|
underline=0,
|
|
command=config.load)
|
|
filemenu.add_command(label="Save full config...",
|
|
underline=0,
|
|
command=config.save)
|
|
filemenu.add_separator()
|
|
filemenu.add_command(label="Reset all to default",
|
|
underline=0,
|
|
command=self.cliopts.reset)
|
|
filemenu.add_command(label="Clear all",
|
|
underline=0,
|
|
command=self.cliopts.clear)
|
|
filemenu.add_separator()
|
|
filemenu.add_command(label="Quit",
|
|
underline=0,
|
|
command=self.close_app)
|
|
|
|
menubar.add_cascade(label="File", menu=filemenu, underline=0)
|
|
self.config(menu=menubar)
|
|
|
|
def add_containers(self):
|
|
""" Add the paned window containers that
|
|
hold each main area of the gui """
|
|
maincontainer = tk.PanedWindow(self,
|
|
sashrelief=tk.RAISED,
|
|
orient=tk.VERTICAL)
|
|
maincontainer.pack(fill=tk.BOTH, expand=True)
|
|
|
|
topcontainer = tk.PanedWindow(maincontainer,
|
|
sashrelief=tk.RAISED,
|
|
orient=tk.HORIZONTAL)
|
|
maincontainer.add(topcontainer)
|
|
|
|
bottomcontainer = ttk.Frame(maincontainer, height=150)
|
|
maincontainer.add(bottomcontainer)
|
|
|
|
return topcontainer, bottomcontainer
|
|
|
|
def close_app(self):
|
|
""" Close Python. This is here because the graph
|
|
animation function continues to run even when
|
|
tkinter has gone away """
|
|
confirm = messagebox.askokcancel
|
|
confirmtxt = "Processes are still running. Are you sure...?"
|
|
if (self.wrapper.tk_vars["runningtask"].get()
|
|
and not confirm("Close", confirmtxt)):
|
|
return
|
|
if self.wrapper.tk_vars["runningtask"].get():
|
|
self.wrapper.task.terminate()
|
|
self.images.delete_preview()
|
|
self.quit()
|
|
exit()
|
|
|
|
|
|
class Gui(object):
|
|
""" The GUI process. """
|
|
def __init__(self, arguments):
|
|
cmd = sys.argv[0]
|
|
pathscript = os.path.realpath(os.path.dirname(cmd))
|
|
self.args = arguments
|
|
self.root = FaceswapGui(pathscript)
|
|
|
|
def process(self):
|
|
""" Builds the GUI """
|
|
self.root.build_gui(self.args.debug)
|
|
self.root.mainloop()
|