Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: grid save #244

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
31278fa
feat: grid save
bluelovers May 9, 2024
ea13555
refactor: SharedOptsBackup
bluelovers Jun 3, 2024
1183c14
feat: save to `agent-scheduler` folder
bluelovers Jun 4, 2024
fcaf117
feat: save to `agent-scheduler` folder
bluelovers Jun 4, 2024
fcab048
fix: outdir_path_grids_old
bluelovers Jun 4, 2024
689195c
feat: support restart webui
bluelovers Jun 4, 2024
a3c8afe
fix: support restart webui
bluelovers Jun 4, 2024
a3e32b7
feat: auto convert Path to str
bluelovers Jun 7, 2024
7f3406f
feat: controlnet detected map
bluelovers Jun 7, 2024
168f51e
chore: add notice
bluelovers Jun 11, 2024
c928d5c
refactor!: {Under Generate button => Near Generate button}
bluelovers Jun 12, 2024
2df5e50
style: update button style
bluelovers Jun 12, 2024
bd68986
build: avoid miss deps
bluelovers Jun 12, 2024
b55a334
ci: auto build
bluelovers Jun 12, 2024
459c233
build: update build
actions-user Jun 12, 2024
652f1c1
feat: add save_mask
bluelovers Jun 18, 2024
44df258
.
bluelovers Jun 18, 2024
90626d4
style: disable box-shadow
bluelovers Jun 18, 2024
0c36726
build: update build
actions-user Jun 20, 2024
29cf4c0
style!: update layout
bluelovers Jun 20, 2024
5216bac
.
bluelovers Jun 20, 2024
b0a73dc
build: update build
actions-user Jun 20, 2024
d419c3f
feat: add dp_write_prompts_to_file
bluelovers Jun 21, 2024
062605e
chore: update message and notice
bluelovers Jun 21, 2024
a544a7a
feat: simplify_path
bluelovers Jun 21, 2024
08414a2
feat: color log
bluelovers Jun 21, 2024
f2bab4c
chore: disable notice
bluelovers Jun 27, 2024
0b0270b
chore: disable notice
bluelovers Jun 28, 2024
af802d6
fix: avoid simplify `control_net_detectedmap_dir`
bluelovers Aug 12, 2024
d3a32c5
fix: `control_net_detectedmap_dir`
bluelovers Aug 12, 2024
3dacf77
fix: `control_net_detectedmap_dir`
bluelovers Aug 13, 2024
596daf3
chore: disable dp_write_prompts_to_file
bluelovers Aug 13, 2024
0235e8a
fix: disable `control_net_detectedmap_dir`
bluelovers Aug 14, 2024
32bb1af
refactor: update setting
bluelovers Aug 16, 2024
11abf89
feat: ad_save_images_dir
bluelovers Aug 18, 2024
4b92d2e
feat: torch_gc
bluelovers Nov 26, 2024
1e6ae6e
chore: torch_gc
bluelovers Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: build

on:
workflow_dispatch:
push:
branches:
- main
- patch-1
paths:
- ui/**/*
- .github/**/*

# schedule:
## https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#scheduled-events-schedule
## ┌───────────── minute (0 - 59)
## │ ┌───────────── hour (0 - 23)
## │ │ ┌───────────── day of the month (1 - 31)
## │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
## │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
## │ │ │ │ │
## │ │ │ │ │
## │ │ │ │ │
## * * * * *
# - cron: '* * 1 * *'
# - cron: '* * 15 * *'

jobs:
main-action:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

strategy:
matrix:
node-version: [ 22 ]

steps:
-
uses: actions/checkout@main
with:
fetch-depth: 2
token: ${{ secrets.GITHUB_TOKEN }}
-
name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@main
with:
node-version: ${{ matrix.node-version }}
-
name: get yarn cache dir
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
-
name: set cache id
id: id-cache
run: echo "::set-output name=id::${GITHUB_SHA}"
-
name: echo var
run: |
echo ${{ steps.yarn-cache.outputs.dir }}
echo ${{ steps.id-cache.outputs.id }}
echo ${GITHUB_SHA}
-
name: yarn cache
uses: bluelovers/github-actions-cache@2020011001
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ steps.id-cache.outputs.id }}
restore-keys: |
${{ runner.os }}-yarn-
-
name: setup git config
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
-
name: install deps
run: |
cd ./ui
yarn install --frozen-lockfile
yarn run ci:install
-
name: run script
if: success()
# env:
run: |
cd ./ui
yarn run ci:build
-
name: Push changes
if: success()
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
118 changes: 118 additions & 0 deletions agent_scheduler/shared_opts_backup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from pathlib import Path, PurePath
import gradio as gr
from typing import Union


def simplify_path(input_path: Union[PurePath, str]) -> Path:
# 如果输入是字符串,将其转换为 Path 对象
if isinstance(input_path, str):
input_path = Path(input_path)

parts = []
for part in input_path.parts:
if part == '..':
if parts and parts[-1] != '..' and parts[-1] != '/' and parts[-1] != input_path.root:
parts.pop()
else:
parts.append(part)
elif part != '.' and part != '':
parts.append(part)

# 如果路径是绝对路径,保留根路径
if input_path.is_absolute():
simplified_path = Path(input_path.root, *parts)
else:
simplified_path = Path(*parts)

return simplified_path

class SharedOptsBackup:
"""
A class used to backup and restore shared options.

Attributes
----------
shared_opts : dict
The shared options to be backed up and restored.
backup : dict
A dictionary to store the backup of shared options.

Methods
-------
set_shared_opts_core(key: str, value)
Sets a shared option and backs it up only if it is not already backed up.

set_shared_opts(**kwargs)
Sets multiple shared options and backs them up.

restore_shared_opts()
Restores the shared options from the backup.
"""

def __init__(self, shared_opts):
"""
Constructs all the necessary attributes for the SharedOptsBackup object.

Parameters
----------
shared_opts : dict
The shared options to be backed up and restored.
"""
self.shared_opts = shared_opts
self.backup = {}

# gr.Info(f"[AgentScheduler] backup shared opts")

def set_shared_opts_core(self, key: str, value):
"""
Sets a shared option and backs it up only if it is not already backed up.

Parameters
----------
key : str
The key of the shared option to be set.
value : any
The value to be set for the shared option.
"""
if not self.is_backup_exists(key):
old = getattr(self.shared_opts, key, None)
self.backup[key] = old
print(f"[AgentScheduler] [backup] {key}: {old}")

if isinstance(value, (Path, PurePath)):
if key != "control_net_detectedmap_dir":
value = simplify_path(value)

value = str(value.as_posix())

self.shared_opts.set(key, value)
if self.backup[key] != value:
print(f"\33[32m[AgentScheduler] [change] {key}: {value}\33[0m")

def set_shared_opts(self, **kwargs):
"""
Sets multiple shared options and backs them up.

Parameters
----------
kwargs : dict
The key-value pairs of shared options to be set.
"""
for attr, value in kwargs.items():
self.set_shared_opts_core(attr, value)

def is_backup_exists(self, key: str):
return key in self.backup

def get_backup_value(self, key: str):
return self.backup.get(key) if self.is_backup_exists(key) else getattr(self.shared_opts, key, None)

def restore_shared_opts(self):
"""
Restores the shared options from the backup.
"""
for attr, value in self.backup.items():
self.shared_opts.set(attr, value)
print(f"\33[32m[AgentScheduler] [restore] {attr}: {value}\33[0m")

# gr.Info(f"[AgentScheduler] restore shared opts")
Loading