code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def _isURITrustableAndTrusted(self, URIToTest):
"""Returns a tuple of booleans: (trustable, trusted).
A given URI is "trustable" if it uses HTTP or HTTPS (constants.TRUSTABLE_WEB_PROTOCOLS).
A given URI is "trusted" if it matches an entry in the trustedDomains config.
Such an en... | Returns a tuple of booleans: (trustable, trusted).
A given URI is "trustable" if it uses HTTP or HTTPS (constants.TRUSTABLE_WEB_PROTOCOLS).
A given URI is "trusted" if it matches an entry in the trustedDomains config.
Such an entry is considered matching if the domain is the same and th... | _isURITrustableAndTrusted | python | Syncplay/syncplay | syncplay/client.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/client.py | Apache-2.0 |
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
"""Retry calling the decorated function using an exponential backoff.
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
:param Exceptio... | Retry calling the decorated function using an exponential backoff.
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
:param ExceptionToCheck: the exception to check. may be a tuple of
excpetions to chec... | retry | python | Syncplay/syncplay | syncplay/utils.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/utils.py | Apache-2.0 |
def write(self, fp):
"""Write an .ini-format representation of the configuration state."""
if self._defaults:
fp.write("[%s]\n" % DEFAULTSECT)
for (key, value) in list(self._defaults.items()):
fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
... | Write an .ini-format representation of the configuration state. | write | python | Syncplay/syncplay | syncplay/ui/ConfigurationGetter.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/ui/ConfigurationGetter.py | Apache-2.0 |
def _qInstallMessageHandler(handler):
"""Install a message handler that works in all bindings
Args:
handler: A function that takes 3 arguments, or None
"""
def messageOutputHandler(*args):
# In Qt4 bindings, message handlers are passed 2 arguments
# In Qt5 bindings, message hand... | Install a message handler that works in all bindings
Args:
handler: A function that takes 3 arguments, or None
| _qInstallMessageHandler | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _wrapinstance(ptr, base=None):
"""Enable implicit cast of pointer to most suitable class
This behaviour is available in sip per default.
Based on http://nathanhorne.com/pyqtpyside-wrap-instance
Usage:
This mechanism kicks in under these circumstances.
1. Qt.py is using PySide 1 or... | Enable implicit cast of pointer to most suitable class
This behaviour is available in sip per default.
Based on http://nathanhorne.com/pyqtpyside-wrap-instance
Usage:
This mechanism kicks in under these circumstances.
1. Qt.py is using PySide 1 or 2.
2. A `base` argument is not pr... | _wrapinstance | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _isvalid(object):
"""Check if the object is valid to use in Python runtime.
Usage:
See :func:`QtCompat.isValid()`
Arguments:
object (QObject): QObject to check the validity of.
"""
if hasattr(Qt, "_shiboken2"):
return getattr(Qt, "_shiboken2").isValid(object)
elif... | Check if the object is valid to use in Python runtime.
Usage:
See :func:`QtCompat.isValid()`
Arguments:
object (QObject): QObject to check the validity of.
| _isvalid | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _loadUi(uifile, baseinstance=None):
"""Dynamically load a user interface from the given `uifile`
This function calls `uic.loadUi` if using PyQt bindings,
else it implements a comparable binding for PySide.
Documentation:
http://pyqt.sourceforge.net/Docs/PyQt5/designer.html#PyQt5.uic.loadUi... | Dynamically load a user interface from the given `uifile`
This function calls `uic.loadUi` if using PyQt bindings,
else it implements a comparable binding for PySide.
Documentation:
http://pyqt.sourceforge.net/Docs/PyQt5/designer.html#PyQt5.uic.loadUi
Arguments:
uifile (str): Absolute... | _loadUi | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _loadCustomWidgets(self, etree):
"""
Workaround to pyside-77 bug.
From QUiLoader doc we should use registerCustomWidget method.
But this causes a segfault on some platforms.
Instead we fetch from customwidgets DOM node the python clas... |
Workaround to pyside-77 bug.
From QUiLoader doc we should use registerCustomWidget method.
But this causes a segfault on some platforms.
Instead we fetch from customwidgets DOM node the python class
objects. Then we can directly use them... | _loadCustomWidgets | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def headerToModule(header):
"""
Translate a header file to python module path
foo/bar.h => foo.bar
"""
# Remove header extension
module = os.path.splitext(header)[0]
# Replace os ... |
Translate a header file to python module path
foo/bar.h => foo.bar
| headerToModule | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def createWidget(self, class_name, parent=None, name=""):
"""Called for each widget defined in ui file
Overridden here to populate `baseinstance` instead.
"""
if parent is None and self.baseinstance:
# Supposed to create the top-leve... | Called for each widget defined in ui file
Overridden here to populate `baseinstance` instead.
| createWidget | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _import_sub_module(module, name):
"""import_sub_module will mimic the function of importlib.import_module"""
module = __import__(module.__name__ + "." + name)
for level in name.split("."):
module = getattr(module, level)
return module | import_sub_module will mimic the function of importlib.import_module | _import_sub_module | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _reassign_misplaced_members(binding):
"""Apply misplaced members from `binding` to Qt.py
Arguments:
binding (dict): Misplaced members
"""
for src, dst in _misplaced_members[binding].items():
dst_value = None
src_parts = src.split(".")
src_module = src_parts[0]
... | Apply misplaced members from `binding` to Qt.py
Arguments:
binding (dict): Misplaced members
| _reassign_misplaced_members | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _build_compatibility_members(binding, decorators=None):
"""Apply `binding` to QtCompat
Arguments:
binding (str): Top level binding in _compatibility_members.
decorators (dict, optional): Provides the ability to decorate the
original Qt methods when needed by a binding. This can ... | Apply `binding` to QtCompat
Arguments:
binding (str): Top level binding in _compatibility_members.
decorators (dict, optional): Provides the ability to decorate the
original Qt methods when needed by a binding. This can be used
to change the returned value to a standard valu... | _build_compatibility_members | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _pyside6():
"""Initialise PySide6
These functions serve to test the existence of a binding
along with set it up in such a way that it aligns with
the final step; adding members from the original binding
to Qt.py
"""
import PySide6 as module
extras = ["QtUiTools"]
try:
... | Initialise PySide6
These functions serve to test the existence of a binding
along with set it up in such a way that it aligns with
the final step; adding members from the original binding
to Qt.py
| _pyside6 | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _pyside2():
"""Initialise PySide2
These functions serve to test the existence of a binding
along with set it up in such a way that it aligns with
the final step; adding members from the original binding
to Qt.py
"""
import PySide2 as module
extras = ["QtUiTools"]
try:
... | Initialise PySide2
These functions serve to test the existence of a binding
along with set it up in such a way that it aligns with
the final step; adding members from the original binding
to Qt.py
| _pyside2 | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _standardizeQFileDialog(some_function):
"""Decorator that makes PyQt4 return conform to other bindings"""
def wrapper(*args, **kwargs):
ret = (some_function(*args, **kwargs))
# PyQt4 only returns the selected filename, force it to a
# standard return of the selec... | Decorator that makes PyQt4 return conform to other bindings | _standardizeQFileDialog | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _convert(lines):
"""Convert compiled .ui file from PySide2 to Qt.py
Arguments:
lines (list): Each line of of .ui file
Usage:
>> with open("myui.py") as f:
.. lines = _convert(f.readlines())
"""
def parse(line):
line = line.replace("from PySide2 import", "fro... | Convert compiled .ui file from PySide2 to Qt.py
Arguments:
lines (list): Each line of of .ui file
Usage:
>> with open("myui.py") as f:
.. lines = _convert(f.readlines())
| _convert | python | Syncplay/syncplay | syncplay/vendor/Qt.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/Qt.py | Apache-2.0 |
def _add(self, xer, primary, type):
"""
Private method for adding a descriptor from the event loop.
It takes care of adding it if new or modifying it if already added
for another state (read -> read/write for example).
"""
if xer not in primary:
primary[xer]... |
Private method for adding a descriptor from the event loop.
It takes care of adding it if new or modifying it if already added
for another state (read -> read/write for example).
| _add | python | Syncplay/syncplay | syncplay/vendor/qt5reactor.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/qt5reactor.py | Apache-2.0 |
def _remove(self, xer, primary):
"""
Private method for removing a descriptor from the event loop.
It does the inverse job of _add, and also add a check in case of the fd
has gone away.
"""
if xer in primary:
notifier = primary.pop(xer)
notifier.s... |
Private method for removing a descriptor from the event loop.
It does the inverse job of _add, and also add a check in case of the fd
has gone away.
| _remove | python | Syncplay/syncplay | syncplay/vendor/qt5reactor.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/qt5reactor.py | Apache-2.0 |
def doIteration(self, delay=None, fromqt=False):
"""This method is called by a Qt timer or by network activity on a file descriptor"""
if not self.running and self._blockApp:
self._blockApp.quit()
self._timer.stop()
if delay is None:
delay = 0
delay = max(... | This method is called by a Qt timer or by network activity on a file descriptor | doIteration | python | Syncplay/syncplay | syncplay/vendor/qt5reactor.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/qt5reactor.py | Apache-2.0 |
def iterate(self, delay=None, fromqt=False):
"""See twisted.internet.interfaces.IReactorCore.iterate."""
self.runUntilCurrent()
self.doEvents()
self.doIteration(delay, fromqt=fromqt) | See twisted.internet.interfaces.IReactorCore.iterate. | iterate | python | Syncplay/syncplay | syncplay/vendor/qt5reactor.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/qt5reactor.py | Apache-2.0 |
def theme():
""" Uses the Windows Registry to detect if the user is using Dark Mode """
# Registry will return 0 if Windows is in Dark Mode and 1 if Windows is in Light Mode. This dictionary converts that output into the text that the program is expecting.
valueMeaning = {0: "Dark", 1: "Light"}
# In HKE... | Uses the Windows Registry to detect if the user is using Dark Mode | theme | python | Syncplay/syncplay | syncplay/vendor/darkdetect/_windows_detect.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/darkdetect/_windows_detect.py | Apache-2.0 |
def __init__(self, ipc_socket, callback=None, quit_callback=None):
"""Create the wrapper.
*ipc_socket* is the pipe name. (Not including \\\\.\\pipe\\)
*callback(json_data)* is the function for recieving events.
*quit_callback* is called when the socket connection dies.
"""
... | Create the wrapper.
*ipc_socket* is the pipe name. (Not including \\.\pipe\)
*callback(json_data)* is the function for recieving events.
*quit_callback* is called when the socket connection dies.
| __init__ | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def send(self, data):
"""Send *data* to the pipe, encoded as JSON."""
try:
self.socket.send_bytes(json.dumps(data).encode('utf-8') + b'\n')
except OSError as ex:
raise ex | Send *data* to the pipe, encoded as JSON. | send | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def run(self):
"""Process pipe events. Do not run this directly. Use *start*."""
data = b''
try:
while True:
current_data = self.socket.recv_bytes(2048)
if current_data == b'':
break
data += current_data
... | Process pipe events. Do not run this directly. Use *start*. | run | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def __init__(self, ipc_socket, callback=None, quit_callback=None):
"""Create the wrapper.
*ipc_socket* is the path to the socket.
*callback(json_data)* is the function for recieving events.
*quit_callback* is called when the socket connection dies.
"""
self.ipc_socket = ... | Create the wrapper.
*ipc_socket* is the path to the socket.
*callback(json_data)* is the function for recieving events.
*quit_callback* is called when the socket connection dies.
| __init__ | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def send(self, data):
"""Send *data* to the socket, encoded as JSON."""
if self.socket is None:
raise BrokenPipeError("socket is closed")
self.socket.send(json.dumps(data).encode('utf-8') + b'\n') | Send *data* to the socket, encoded as JSON. | send | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def run(self):
"""Process socket events. Do not run this directly. Use *start*."""
data = b''
try:
while True:
current_data = self.socket.recv(1024)
if current_data == b'':
break
data += current_data
... | Process socket events. Do not run this directly. Use *start*. | run | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def __init__(self, ipc_socket, mpv_location=None, env=None, **kwargs):
"""
Create and start the MPV process. Will block until socket/pipe is available.
*ipc_socket* is the path to the Unix/Linux socket or name of the Windows pipe.
*mpv_location* is the path to mpv. If left unset it trie... |
Create and start the MPV process. Will block until socket/pipe is available.
*ipc_socket* is the path to the Unix/Linux socket or name of the Windows pipe.
*mpv_location* is the path to mpv. If left unset it tries the one in the PATH.
All other arguments are forwarded to MPV as comman... | __init__ | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def __init__(self, ipc_socket, callback=None, quit_callback=None):
"""Create the wrapper.
*ipc_socket* is the path to the Unix/Linux socket or name of the Windows pipe.
*callback(event_name, data)* is the function for recieving events.
*quit_callback* is called when the socket connectio... | Create the wrapper.
*ipc_socket* is the path to the Unix/Linux socket or name of the Windows pipe.
*callback(event_name, data)* is the function for recieving events.
*quit_callback* is called when the socket connection to MPV dies.
| __init__ | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def event_callback(self, data):
"""Internal callback for recieving events from MPV."""
if "request_id" in data:
self.cid_result[data["request_id"]] = data
self.cid_wait[data["request_id"]].set()
elif "event" in data:
self.callback(data["event"], data) | Internal callback for recieving events from MPV. | event_callback | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def command(self, command, *args):
"""
Issue a command to MPV. Will block until completed or timeout is reached.
*command* is the name of the MPV command
All further arguments are forwarded to the MPV command.
Throws TimeoutError if timeout of 120 seconds is reached.
""... |
Issue a command to MPV. Will block until completed or timeout is reached.
*command* is the name of the MPV command
All further arguments are forwarded to the MPV command.
Throws TimeoutError if timeout of 120 seconds is reached.
| command | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def run(self):
"""Process socket events. Do not run this directly. Use *start*."""
while True:
event = self.queue.get()
if event == "quit":
break
try:
event[0](*event[1])
except Exception:
log.error("EventHan... | Process socket events. Do not run this directly. Use *start*. | run | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def __init__(self, start_mpv=True, ipc_socket=None, mpv_location=None,
log_handler=None, loglevel=None, quit_callback=None, **kwargs):
"""
Create the interface to MPV and process instance.
*start_mpv* will start an MPV process if true. (Default: True)
*ipc_socket* is th... |
Create the interface to MPV and process instance.
*start_mpv* will start an MPV process if true. (Default: True)
*ipc_socket* is the path to the Unix/Linux socket or name of Windows pipe. (Default: Random Temp File)
*mpv_location* is the location of MPV for *start_mpv*. (Default: Use M... | __init__ | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def bind_event(self, name, callback):
"""
Bind a callback to an MPV event.
*name* is the MPV event name.
*callback(event_data)* is the function to call.
"""
if name not in self.event_bindings:
self.event_bindings[name] = set()
self.event_bindings[name... |
Bind a callback to an MPV event.
*name* is the MPV event name.
*callback(event_data)* is the function to call.
| bind_event | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def on_event(self, name):
"""
Decorator to bind a callback to an MPV event.
@on_event(name)
def my_callback(event_data):
pass
"""
def wrapper(func):
self.bind_event(name, func)
return func
return wrapper |
Decorator to bind a callback to an MPV event.
@on_event(name)
def my_callback(event_data):
pass
| on_event | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def on_key_press(self, name):
"""
Decorator to bind a callback to an MPV keypress event.
@on_key_press(key_name)
def my_callback():
pass
"""
def wrapper(func):
self.bind_key_press(name, func)
return func
return wrapper |
Decorator to bind a callback to an MPV keypress event.
@on_key_press(key_name)
def my_callback():
pass
| on_key_press | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def bind_key_press(self, name, callback):
"""
Bind a callback to an MPV keypress event.
*name* is the key symbol.
*callback()* is the function to call.
"""
self.keybind_lock.acquire()
keybind_id = self.keybind_id
self.keybind_id += 1
self.keybind_... |
Bind a callback to an MPV keypress event.
*name* is the key symbol.
*callback()* is the function to call.
| bind_key_press | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def bind_property_observer(self, name, callback):
"""
Bind a callback to an MPV property change.
*name* is the property name.
*callback(name, data)* is the function to call.
Returns a unique observer ID needed to destroy the observer.
"""
self.observer_lock.acqu... |
Bind a callback to an MPV property change.
*name* is the property name.
*callback(name, data)* is the function to call.
Returns a unique observer ID needed to destroy the observer.
| bind_property_observer | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def property_observer(self, name):
"""
Decorator to bind a callback to an MPV property change.
@property_observer(property_name)
def my_callback(name, data):
pass
"""
def wrapper(func):
self.bind_property_observer(name, func)
return fu... |
Decorator to bind a callback to an MPV property change.
@property_observer(property_name)
def my_callback(name, data):
pass
| property_observer | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def wait_for_property(self, name):
"""
Waits for the value of a property to change.
*name* is the name of the property.
"""
event = threading.Event()
first_event = True
def handler(*_):
nonlocal first_event
if first_event == True:
... |
Waits for the value of a property to change.
*name* is the name of the property.
| wait_for_property | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def terminate(self, join=True):
"""Terminate the connection to MPV and process (if *start_mpv* is used)."""
if self.mpv_process:
self.mpv_process.stop()
if self.mpv_inter:
self.mpv_inter.stop(join)
self.event_handler.stop(join) | Terminate the connection to MPV and process (if *start_mpv* is used). | terminate | python | Syncplay/syncplay | syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | https://github.com/Syncplay/syncplay/blob/master/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py | Apache-2.0 |
def caption_images(
caption_text: str,
images_dir: str,
overwrite: bool,
caption_ext: str,
prefix: str,
postfix: str,
find_text: str,
replace_text: str,
):
"""
Captions images in a given directory with a given caption text.
Args:
caption_text (str): The text to be us... |
Captions images in a given directory with a given caption text.
Args:
caption_text (str): The text to be used as the caption.
images_dir (str): The directory containing the images to be captioned.
overwrite (bool): Whether to overwrite existing captions.
caption_ext (str): The ... | caption_images | python | bmaltais/kohya_ss | kohya_gui/basic_caption_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/basic_caption_gui.py | Apache-2.0 |
def list_images_dirs(path):
"""
Lists directories within a specified path and updates the current image directory.
Parameters:
path (str): The directory path to list image directories from.
Returns:
list: A list of directories within the specified path.
... |
Lists directories within a specified path and updates the current image directory.
Parameters:
path (str): The directory path to list image directories from.
Returns:
list: A list of directories within the specified path.
| list_images_dirs | python | bmaltais/kohya_ss | kohya_gui/basic_caption_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/basic_caption_gui.py | Apache-2.0 |
def get_images_in_directory(directory_path):
"""
Returns a list of image file paths found in the provided directory path.
Parameters:
- directory_path: A string representing the path to the directory to search for images.
Returns:
- A list of strings, where each string is the full path to an i... |
Returns a list of image file paths found in the provided directory path.
Parameters:
- directory_path: A string representing the path to the directory to search for images.
Returns:
- A list of strings, where each string is the full path to an image file found in the specified directory.
| get_images_in_directory | python | bmaltais/kohya_ss | kohya_gui/blip2_caption_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/blip2_caption_gui.py | Apache-2.0 |
def generate_caption(
file_list,
processor,
model,
device,
caption_file_ext=".txt",
num_beams=5,
repetition_penalty=1.5,
length_penalty=1.2,
max_new_tokens=40,
min_new_tokens=20,
do_sample=True,
temperature=1.0,
top_p=0.0,
):
"""
Fetches and processes each ima... |
Fetches and processes each image in file_list, generates captions based on the image, and writes the generated captions to a file.
Parameters:
- file_list: A list of file paths pointing to the images to be captioned.
- processor: The preprocessor for the BLIP2 model.
- model: The BLIP2 model to be... | generate_caption | python | bmaltais/kohya_ss | kohya_gui/blip2_caption_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/blip2_caption_gui.py | Apache-2.0 |
def caption_images_beam_search(
directory_path,
num_beams,
repetition_penalty,
length_penalty,
min_new_tokens,
max_new_tokens,
caption_file_ext,
):
"""
Captions all images in the specified directory using the provided prompt.
Parameters:
- directory_path: A string representi... |
Captions all images in the specified directory using the provided prompt.
Parameters:
- directory_path: A string representing the path to the directory containing the images to be captioned.
| caption_images_beam_search | python | bmaltais/kohya_ss | kohya_gui/blip2_caption_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/blip2_caption_gui.py | Apache-2.0 |
def caption_images_nucleus(
directory_path,
do_sample,
temperature,
top_p,
min_new_tokens,
max_new_tokens,
caption_file_ext,
):
"""
Captions all images in the specified directory using the provided prompt.
Parameters:
- directory_path: A string representing the path to the d... |
Captions all images in the specified directory using the provided prompt.
Parameters:
- directory_path: A string representing the path to the directory containing the images to be captioned.
| caption_images_nucleus | python | bmaltais/kohya_ss | kohya_gui/blip2_caption_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/blip2_caption_gui.py | Apache-2.0 |
def caption_images(
train_data_dir: str,
caption_file_ext: str,
batch_size: int,
num_beams: int,
top_p: float,
max_length: int,
min_length: int,
beam_search: bool,
prefix: str = "",
postfix: str = "",
) -> None:
"""
Automatically generates captions for images in the speci... |
Automatically generates captions for images in the specified directory using the BLIP model.
This function prepares and executes a command-line script to process images in batches, applying advanced
NLP techniques for caption generation. It supports customization of the captioning process through various
... | caption_images | python | bmaltais/kohya_ss | kohya_gui/blip_caption_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/blip_caption_gui.py | Apache-2.0 |
def noise_offset_type_change(
noise_offset_type: str,
) -> Tuple[gr.Group, gr.Group]:
"""
Returns a tuple of Gradio Groups with visibility set based on the noise offset type.
Parameters:
noise_offset_type (str): The selected noise offset type.
... |
Returns a tuple of Gradio Groups with visibility set based on the noise offset type.
Parameters:
noise_offset_type (str): The selected noise offset type.
Returns:
Tuple[gr.Group, gr.Group]: A tuple containing two Gradio Group elements with their vis... | noise_offset_type_change | python | bmaltais/kohya_ss | kohya_gui/class_advanced_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_advanced_training.py | Apache-2.0 |
def __init__(
self,
sdxl_checkbox: gr.Checkbox,
learning_rate_value: float = "1e-6",
lr_scheduler_value: str = "constant",
lr_warmup_value: float = "0",
lr_warmup_steps_value: int = 0,
finetuning: bool = False,
dreambooth: bool = False,
config: dic... |
Initializes the BasicTraining object with the given parameters.
Args:
sdxl_checkbox (gr.Checkbox): Checkbox to enable SDXL training.
learning_rate_value (str): Initial learning rate value.
lr_scheduler_value (str): Initial learning rate scheduler value.
... | __init__ | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def initialize_ui_components(self) -> None:
"""
Initializes the UI components for the training settings.
"""
# Initialize the training controls
self.init_training_controls()
# Initialize the precision and resources controls
self.init_precision_and_resources_contro... |
Initializes the UI components for the training settings.
| initialize_ui_components | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def init_training_controls(self) -> None:
"""
Initializes the training controls for the model.
"""
# Create a row for the training controls
with gr.Row():
# Initialize the train batch size slider
self.train_batch_size = gr.Slider(
minimum=1... |
Initializes the training controls for the model.
| init_training_controls | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def init_precision_and_resources_controls(self) -> None:
"""
Initializes the precision and resources controls for the model.
"""
with gr.Row():
# Initialize the seed textbox
self.seed = gr.Number(
label="Seed",
# precision=0,
... |
Initializes the precision and resources controls for the model.
| init_precision_and_resources_controls | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def init_lr_and_optimizer_controls(self) -> None:
"""
Initializes the learning rate and optimizer controls for the model.
"""
with gr.Row():
# Initialize the learning rate scheduler dropdown
self.lr_scheduler = gr.Dropdown(
label="LR Scheduler",
... |
Initializes the learning rate and optimizer controls for the model.
| init_lr_and_optimizer_controls | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def init_grad_and_lr_controls(self) -> None:
"""
Initializes the gradient and learning rate controls for the model.
"""
with gr.Row():
# Initialize the maximum gradient norm slider
self.max_grad_norm = gr.Number(label='Max grad norm', value=1.0, interactive=True)
... |
Initializes the gradient and learning rate controls for the model.
| init_grad_and_lr_controls | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def init_learning_rate_controls(self) -> None:
"""
Initializes the learning rate controls for the model.
"""
with gr.Row():
# Adjust visibility based on training modes
lr_label = (
"Learning rate Unet"
if self.finetuning or self.dre... |
Initializes the learning rate controls for the model.
| init_learning_rate_controls | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def init_scheduler_controls(self) -> None:
"""
Initializes the scheduler controls for the model.
"""
with gr.Row(visible=not self.finetuning):
# Initialize the learning rate scheduler number of cycles textbox
self.lr_scheduler_num_cycles = gr.Number(
... |
Initializes the scheduler controls for the model.
| init_scheduler_controls | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def init_resolution_and_bucket_controls(self) -> None:
"""
Initializes the resolution and bucket controls for the model.
"""
with gr.Row(visible=not self.finetuning):
# Initialize the maximum resolution textbox
self.max_resolution = gr.Textbox(
lab... |
Initializes the resolution and bucket controls for the model.
| init_resolution_and_bucket_controls | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def setup_sdxl_checkbox_behavior(self) -> None:
"""
Sets up the behavior of the SDXL checkbox based on the finetuning and dreambooth flags.
"""
self.sdxl_checkbox.change(
self.update_learning_rate_te,
inputs=[
self.sdxl_checkbox,
gr... |
Sets up the behavior of the SDXL checkbox based on the finetuning and dreambooth flags.
| setup_sdxl_checkbox_behavior | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def update_learning_rate_te(
self,
sdxl_checkbox: gr.Checkbox,
finetuning: bool,
dreambooth: bool,
) -> Tuple[gr.Number, gr.Number, gr.Number]:
"""
Updates the visibility of the learning rate TE, TE1, and TE2 based on the SDXL checkbox and finetuning/dreambooth flags.... |
Updates the visibility of the learning rate TE, TE1, and TE2 based on the SDXL checkbox and finetuning/dreambooth flags.
Args:
sdxl_checkbox (gr.Checkbox): The SDXL checkbox.
finetuning (bool): Whether finetuning is enabled.
dreambooth (bool): Whether dreambooth is ... | update_learning_rate_te | python | bmaltais/kohya_ss | kohya_gui/class_basic_training.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_basic_training.py | Apache-2.0 |
def execute_command(self, run_cmd: str, **kwargs):
"""
Execute a command if no other command is currently running.
Parameters:
- run_cmd (str): The command to execute.
- **kwargs: Additional keyword arguments to pass to subprocess.Popen.
"""
if self.process and s... |
Execute a command if no other command is currently running.
Parameters:
- run_cmd (str): The command to execute.
- **kwargs: Additional keyword arguments to pass to subprocess.Popen.
| execute_command | python | bmaltais/kohya_ss | kohya_gui/class_command_executor.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_command_executor.py | Apache-2.0 |
def kill_command(self):
"""
Kill the currently running command and its child processes.
"""
if self.is_running():
try:
# Get the parent process and kill all its children
parent = psutil.Process(self.process.pid)
for child in par... |
Kill the currently running command and its child processes.
| kill_command | python | bmaltais/kohya_ss | kohya_gui/class_command_executor.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_command_executor.py | Apache-2.0 |
def __init__(
self, headless: bool = False, config_dir: str = None, config: dict = {}
):
"""
Initialize the ConfigurationFile class.
Parameters:
- headless (bool): Whether to run in headless mode.
- config_dir (str): The directory for configuration files.
"""... |
Initialize the ConfigurationFile class.
Parameters:
- headless (bool): Whether to run in headless mode.
- config_dir (str): The directory for configuration files.
| __init__ | python | bmaltais/kohya_ss | kohya_gui/class_configuration_file.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_configuration_file.py | Apache-2.0 |
def list_config_dir(self, path: str) -> list:
"""
List directories in the data directory.
Parameters:
- path (str): The path to list directories from.
Returns:
- list: A list of directories.
"""
self.current_config_dir = path if not path == "" else "."
... |
List directories in the data directory.
Parameters:
- path (str): The path to list directories from.
Returns:
- list: A list of directories.
| list_config_dir | python | bmaltais/kohya_ss | kohya_gui/class_configuration_file.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_configuration_file.py | Apache-2.0 |
def __init__(
self, finetune: bool = False, headless: bool = False, config: dict = {}
):
"""
Initialize the Folders class.
Parameters:
- finetune (bool): Whether to finetune the model.
- headless (bool): Whether to run in headless mode.
"""
self.headl... |
Initialize the Folders class.
Parameters:
- finetune (bool): Whether to finetune the model.
- headless (bool): Whether to run in headless mode.
| __init__ | python | bmaltais/kohya_ss | kohya_gui/class_folders.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_folders.py | Apache-2.0 |
def create_directory_if_not_exists(self, directory: str) -> None:
"""
Create a directory if it does not exist.
Parameters:
- directory (str): The directory to create.
"""
if (
directory is not None
and directory.strip() != ""
and not o... |
Create a directory if it does not exist.
Parameters:
- directory (str): The directory to create.
| create_directory_if_not_exists | python | bmaltais/kohya_ss | kohya_gui/class_folders.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_folders.py | Apache-2.0 |
def load_config(self, config_file_path: str = "./config.toml") -> dict:
"""
Loads the Kohya SS GUI configuration from a TOML file.
Returns:
dict: The configuration data loaded from the TOML file.
"""
try:
# Attempt to load the TOML configuration file from the... |
Loads the Kohya SS GUI configuration from a TOML file.
Returns:
dict: The configuration data loaded from the TOML file.
| load_config | python | bmaltais/kohya_ss | kohya_gui/class_gui_config.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_gui_config.py | Apache-2.0 |
def save_config(self, config: dict, config_file_path: str = "./config.toml"):
"""
Saves the Kohya SS GUI configuration to a TOML file.
Parameters:
- config (dict): The configuration data to save.
"""
# Write the configuration data to the TOML file
with open(f"{co... |
Saves the Kohya SS GUI configuration to a TOML file.
Parameters:
- config (dict): The configuration data to save.
| save_config | python | bmaltais/kohya_ss | kohya_gui/class_gui_config.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_gui_config.py | Apache-2.0 |
def get(self, key: str, default=None):
"""
Retrieves the value of a specified key from the configuration data.
Parameters:
- key (str): The key to retrieve the value for.
- default: The default value to return if the key is not found.
Returns:
The value associat... |
Retrieves the value of a specified key from the configuration data.
Parameters:
- key (str): The key to retrieve the value for.
- default: The default value to return if the key is not found.
Returns:
The value associated with the key, or the default value if the key i... | get | python | bmaltais/kohya_ss | kohya_gui/class_gui_config.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_gui_config.py | Apache-2.0 |
def is_config_loaded(self) -> bool:
"""
Checks if the configuration was loaded from a file.
Returns:
bool: True if the configuration was loaded from a file, False otherwise.
"""
is_loaded = self.config != {}
log.debug(f"Configuration was loaded from file: {is_loa... |
Checks if the configuration was loaded from a file.
Returns:
bool: True if the configuration was loaded from a file, False otherwise.
| is_config_loaded | python | bmaltais/kohya_ss | kohya_gui/class_gui_config.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_gui_config.py | Apache-2.0 |
def create_prompt_file(sample_prompts, output_dir):
"""
Creates a prompt file for image sampling.
Args:
sample_prompts (str): The prompts to use for image sampling.
output_dir (str): The directory where the output images will be saved.
Returns:
str: The path to the prompt file.... |
Creates a prompt file for image sampling.
Args:
sample_prompts (str): The prompts to use for image sampling.
output_dir (str): The directory where the output images will be saved.
Returns:
str: The path to the prompt file.
| create_prompt_file | python | bmaltais/kohya_ss | kohya_gui/class_sample_images.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_sample_images.py | Apache-2.0 |
def initialize_accordion(self):
"""
Initializes the accordion for the Gradio interface.
"""
with gr.Row():
self.sample_every_n_steps = gr.Number(
label="Sample every n steps",
value=self.config.get("samples.sample_every_n_steps", 0),
... |
Initializes the accordion for the Gradio interface.
| initialize_accordion | python | bmaltais/kohya_ss | kohya_gui/class_sample_images.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_sample_images.py | Apache-2.0 |
def __init__(
self,
headless: bool = False,
finetuning: bool = False,
training_type: str = "",
config: dict = {},
sd3_checkbox: gr.Checkbox = False,
) -> None:
"""
Initializes the AdvancedTraining class with given settings.
Parameters:
... |
Initializes the AdvancedTraining class with given settings.
Parameters:
headless (bool): Run in headless mode without GUI.
finetuning (bool): Enable model fine-tuning.
training_type (str): The type of training to be performed.
config (dict): Configuratio... | __init__ | python | bmaltais/kohya_ss | kohya_gui/class_sd3.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_sd3.py | Apache-2.0 |
def noise_offset_type_change(
noise_offset_type: str,
) -> Tuple[gr.Group, gr.Group]:
"""
Returns a tuple of Gradio Groups with visibility set based on the noise offset type.
Parameters:
noise_offset_type (str): The selected noise offset type.
... |
Returns a tuple of Gradio Groups with visibility set based on the noise offset type.
Parameters:
noise_offset_type (str): The selected noise offset type.
Returns:
Tuple[gr.Group, gr.Group]: A tuple containing two Gradio Group elements with their vis... | noise_offset_type_change | python | bmaltais/kohya_ss | kohya_gui/class_sd3.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_sd3.py | Apache-2.0 |
def list_dataset_config_dirs(path: str) -> list:
"""
List directories and toml files in the dataset_config directory.
Parameters:
- path (str): The path to list directories and files from.
Returns:
- list: A list of directories and files.
... |
List directories and toml files in the dataset_config directory.
Parameters:
- path (str): The path to list directories and files from.
Returns:
- list: A list of directories and files.
| list_dataset_config_dirs | python | bmaltais/kohya_ss | kohya_gui/class_source_model.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/class_source_model.py | Apache-2.0 |
def get_executable_path(executable_name: str = None) -> str:
"""
Retrieve and sanitize the path to an executable in the system's PATH.
Args:
executable_name (str): The name of the executable to find.
Returns:
str: The full, sanitized path to the executable if found, otherwise an empty string.
... |
Retrieve and sanitize the path to an executable in the system's PATH.
Args:
executable_name (str): The name of the executable to find.
Returns:
str: The full, sanitized path to the executable if found, otherwise an empty string.
| get_executable_path | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def check_if_model_exist(
output_name: str, output_dir: str, save_model_as: str, headless: bool = False
) -> bool:
"""
Checks if a model with the same name already exists and prompts the user to overwrite it if it does.
Parameters:
output_name (str): The name of the output model.
output_dir (st... |
Checks if a model with the same name already exists and prompts the user to overwrite it if it does.
Parameters:
output_name (str): The name of the output model.
output_dir (str): The directory where the model is saved.
save_model_as (str): The format to save the model as.
headless (bool, opti... | check_if_model_exist | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def output_message(msg: str = "", title: str = "", headless: bool = False) -> None:
"""
Outputs a message to the user, either in a message box or in the log.
Parameters:
msg (str, optional): The message to be displayed. Defaults to an empty string.
title (str, optional): The title of the message bo... |
Outputs a message to the user, either in a message box or in the log.
Parameters:
msg (str, optional): The message to be displayed. Defaults to an empty string.
title (str, optional): The title of the message box. Defaults to an empty string.
headless (bool, optional): If True, the message is logg... | output_message | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_id):
"""
Creates a refresh button that can be used to update UI components.
Parameters:
refresh_component (list or object): The UI component(s) to be refreshed.
refresh_method (callable): The method to be called when ... |
Creates a refresh button that can be used to update UI components.
Parameters:
refresh_component (list or object): The UI component(s) to be refreshed.
refresh_method (callable): The method to be called when the button is clicked.
refreshed_args (dict or callable): The arguments to be passed to th... | create_refresh_button | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def get_file_path(
file_path="", default_extension=".json", extension_name="Config files"
):
"""
Opens a file dialog to select a file, allowing the user to navigate and choose a file with a specific extension.
If no file is selected, returns the initially provided file path or an empty string if not pro... |
Opens a file dialog to select a file, allowing the user to navigate and choose a file with a specific extension.
If no file is selected, returns the initially provided file path or an empty string if not provided.
This function is conditioned to skip the file dialog on macOS or if specific environment vari... | get_file_path | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def get_any_file_path(file_path: str = "") -> str:
"""
Opens a file dialog to select any file, allowing the user to navigate and choose a file.
If no file is selected, returns the initially provided file path or an empty string if not provided.
This function is conditioned to skip the file dialog on mac... |
Opens a file dialog to select any file, allowing the user to navigate and choose a file.
If no file is selected, returns the initially provided file path or an empty string if not provided.
This function is conditioned to skip the file dialog on macOS or if specific environment variables are present,
i... | get_any_file_path | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def get_folder_path(folder_path: str = "") -> str:
"""
Opens a folder dialog to select a folder, allowing the user to navigate and choose a folder.
If no folder is selected, returns the initially provided folder path or an empty string if not provided.
This function is conditioned to skip the folder dia... |
Opens a folder dialog to select a folder, allowing the user to navigate and choose a folder.
If no folder is selected, returns the initially provided folder path or an empty string if not provided.
This function is conditioned to skip the folder dialog on macOS or if specific environment variables are pres... | get_folder_path | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def get_saveasfilename_path(
file_path: str = "",
extensions: str = "*",
extension_name: str = "Config files",
) -> str:
"""
Opens a file dialog to select a file name for saving, allowing the user to specify a file name and location.
If no file is selected, returns the initially provided file pa... |
Opens a file dialog to select a file name for saving, allowing the user to specify a file name and location.
If no file is selected, returns the initially provided file path or an empty string if not provided.
This function is conditioned to skip the file dialog on macOS or if specific environment variable... | get_saveasfilename_path | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def add_pre_postfix(
folder: str = "",
prefix: str = "",
postfix: str = "",
caption_file_ext: str = ".caption",
recursive: bool = False,
) -> None:
"""
Add prefix and/or postfix to the content of caption files within a folder.
If no caption files are found, create one with the requested ... |
Add prefix and/or postfix to the content of caption files within a folder.
If no caption files are found, create one with the requested prefix and/or postfix.
Args:
folder (str): Path to the folder containing caption files.
prefix (str, optional): Prefix to add to the content of the captio... | add_pre_postfix | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def has_ext_files(folder_path: str, file_extension: str) -> bool:
"""
Determines whether any files within a specified folder have a given file extension.
This function iterates through each file in the specified folder and checks if
its extension matches the provided file_extension argument. The search... |
Determines whether any files within a specified folder have a given file extension.
This function iterates through each file in the specified folder and checks if
its extension matches the provided file_extension argument. The search is case-sensitive
and expects file_extension to include the dot ('.'... | has_ext_files | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def find_replace(
folder_path: str = "",
caption_file_ext: str = ".caption",
search_text: str = "",
replace_text: str = "",
) -> None:
"""
Efficiently finds and replaces specified text across all caption files in a given folder.
This function iterates through each caption file matching the ... |
Efficiently finds and replaces specified text across all caption files in a given folder.
This function iterates through each caption file matching the specified extension within the given folder path, replacing all occurrences of the search text with the replacement text. It ensures that the operation only p... | find_replace | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def color_aug_changed(color_aug):
"""
Handles the change in color augmentation checkbox.
This function is called when the color augmentation checkbox is toggled.
If color augmentation is enabled, it disables the cache latent checkbox
and returns a new checkbox with the value set to False and intera... |
Handles the change in color augmentation checkbox.
This function is called when the color augmentation checkbox is toggled.
If color augmentation is enabled, it disables the cache latent checkbox
and returns a new checkbox with the value set to False and interactive set to False.
If color augmenta... | color_aug_changed | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def set_pretrained_model_name_or_path_input(
pretrained_model_name_or_path, refresh_method=None
):
"""
Sets the pretrained model name or path input based on the model type.
This function checks the type of the pretrained model and sets the appropriate
parameters for the model. It also handles the c... |
Sets the pretrained model name or path input based on the model type.
This function checks the type of the pretrained model and sets the appropriate
parameters for the model. It also handles the case where the model list is
set to 'custom' and a refresh method is provided.
Args:
pretraine... | set_pretrained_model_name_or_path_input | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def get_int_or_default(kwargs, key, default_value=0):
"""
Retrieves an integer value from the provided kwargs dictionary based on the given key. If the key is not found,
or the value cannot be converted to an integer, a default value is returned.
Args:
kwargs (dict): A dictionary of keyword arg... |
Retrieves an integer value from the provided kwargs dictionary based on the given key. If the key is not found,
or the value cannot be converted to an integer, a default value is returned.
Args:
kwargs (dict): A dictionary of keyword arguments.
key (str): The key to retrieve from the kwarg... | get_int_or_default | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def get_float_or_default(kwargs, key, default_value=0.0):
"""
Retrieves a float value from the provided kwargs dictionary based on the given key. If the key is not found,
or the value cannot be converted to a float, a default value is returned.
This function attempts to convert the value to a float, wh... |
Retrieves a float value from the provided kwargs dictionary based on the given key. If the key is not found,
or the value cannot be converted to a float, a default value is returned.
This function attempts to convert the value to a float, which works for integers, floats, and strings that
represent va... | get_float_or_default | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def get_str_or_default(kwargs, key, default_value=""):
"""
Retrieves a string value from the provided kwargs dictionary based on the given key. If the key is not found,
or the value is not a string, a default value is returned.
Args:
kwargs (dict): A dictionary of keyword arguments.
key... |
Retrieves a string value from the provided kwargs dictionary based on the given key. If the key is not found,
or the value is not a string, a default value is returned.
Args:
kwargs (dict): A dictionary of keyword arguments.
key (str): The key to retrieve from the kwargs dictionary.
... | get_str_or_default | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def run_cmd_advanced_training(run_cmd: list = [], **kwargs):
"""
This function, run_cmd_advanced_training, dynamically constructs a command line string for advanced training
configurations based on provided keyword arguments (kwargs). Each argument represents a different training parameter
or flag that ... |
This function, run_cmd_advanced_training, dynamically constructs a command line string for advanced training
configurations based on provided keyword arguments (kwargs). Each argument represents a different training parameter
or flag that can be used to customize the training process. The function checks f... | run_cmd_advanced_training | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def verify_image_folder_pattern(folder_path: str) -> bool:
"""
Verify the image folder pattern in the given folder path.
Args:
folder_path (str): The path to the folder containing image folders.
Returns:
bool: True if the image folder pattern is valid, False otherwise.
"""
# In... |
Verify the image folder pattern in the given folder path.
Args:
folder_path (str): The path to the folder containing image folders.
Returns:
bool: True if the image folder pattern is valid, False otherwise.
| verify_image_folder_pattern | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def SaveConfigFile(
parameters,
file_path: str,
exclusion: list = ["file_path", "save_as", "headless", "print_only"],
) -> None:
"""
Saves the configuration parameters to a JSON file, excluding specified keys.
This function iterates over a dictionary of parameters, filters out keys listed
i... |
Saves the configuration parameters to a JSON file, excluding specified keys.
This function iterates over a dictionary of parameters, filters out keys listed
in the `exclusion` list, and saves the remaining parameters to a JSON file
specified by `file_path`.
Args:
parameters (dict): Dictio... | SaveConfigFile | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def save_to_file(content):
"""
Appends the given content to a file named 'print_command.txt' within a 'logs' directory.
This function checks for the existence of a 'logs' directory and creates it if
it doesn't exist. Then, it appends the provided content along with a newline character
to the 'print... |
Appends the given content to a file named 'print_command.txt' within a 'logs' directory.
This function checks for the existence of a 'logs' directory and creates it if
it doesn't exist. Then, it appends the provided content along with a newline character
to the 'print_command.txt' file within this dir... | save_to_file | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def check_duplicate_filenames(
folder_path: str,
image_extension: list = [".gif", ".png", ".jpg", ".jpeg", ".webp"],
) -> None:
"""
Checks for duplicate image filenames in a given folder path.
This function walks through the directory structure of the given folder path,
and logs a warning if it... |
Checks for duplicate image filenames in a given folder path.
This function walks through the directory structure of the given folder path,
and logs a warning if it finds files with the same name but different image extensions.
This can lead to issues during training if not handled properly.
Args:... | check_duplicate_filenames | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def validate_model_path(pretrained_model_name_or_path: str) -> bool:
"""
Validates the pretrained model name or path against Hugging Face models or local paths.
Args:
pretrained_model_name_or_path (str): The pretrained model name or path to validate.
Returns:
bool: True if the path is ... |
Validates the pretrained model name or path against Hugging Face models or local paths.
Args:
pretrained_model_name_or_path (str): The pretrained model name or path to validate.
Returns:
bool: True if the path is a valid Hugging Face model or exists locally; False otherwise.
| validate_model_path | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def is_file_writable(file_path: str) -> bool:
"""
Checks if a file is writable.
Args:
file_path (str): The path to the file to be checked.
Returns:
bool: True if the file is writable, False otherwise.
"""
# If the file does not exist, it is considered writable
if not os.pat... |
Checks if a file is writable.
Args:
file_path (str): The path to the file to be checked.
Returns:
bool: True if the file is writable, False otherwise.
| is_file_writable | python | bmaltais/kohya_ss | kohya_gui/common_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/common_gui.py | Apache-2.0 |
def gradio_convert_lcm_tab(headless=False):
"""
Creates a Gradio tab for converting a model to an LCM model.
Args:
headless (bool): If True, the tab will be created without any visible elements.
Returns:
None
"""
current_model_dir = os.path.join(scriptdir, "outputs")
current_save_d... |
Creates a Gradio tab for converting a model to an LCM model.
Args:
headless (bool): If True, the tab will be created without any visible elements.
Returns:
None
| gradio_convert_lcm_tab | python | bmaltais/kohya_ss | kohya_gui/convert_lcm_gui.py | https://github.com/bmaltais/kohya_ss/blob/master/kohya_gui/convert_lcm_gui.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.