Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Akegarasu committed Jul 12, 2023
1 parent b74514c commit 58ad041
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion frontend
Submodule frontend updated 39 files
+3 −3 dist/404.html
+1 −1 dist/assets/404.cd992b14.js
+1 −1 dist/assets/404.html.9772e0b3.js
+1 −1 dist/assets/about.html.f5155240.js
+22 −22 dist/assets/app.f5f2abf8.js
+1 −0 dist/assets/basic.html.16a45f32.js
+1 −1 dist/assets/basic.html.8b88cf7e.js
+0 −1 dist/assets/basic.html.f70a3f10.js
+1 −0 dist/assets/index.html.3a528c00.js
+1 −1 dist/assets/index.html.b9f0fb9c.js
+1 −1 dist/assets/index.html.c99af38e.js
+0 −1 dist/assets/index.html.dc5838ca.js
+11 −0 dist/assets/layout.00b524fc.js
+0 −11 dist/assets/layout.832a8147.js
+0 −1 dist/assets/master.html.3cab76fc.js
+1 −1 dist/assets/master.html.8289906f.js
+1 −0 dist/assets/master.html.aa9758bd.js
+1 −1 dist/assets/params.html.660d78ae.js
+1 −1 dist/assets/settings.html.6ddd9e68.js
+1 −0 dist/assets/style.0d17df4e.css
+0 −1 dist/assets/style.a0675c8c.css
+1 −1 dist/assets/tagger.html.2522bb8b.js
+1 −0 dist/assets/task.html.4e4c8633.js
+1 −0 dist/assets/task.html.8188fc29.js
+1 −1 dist/assets/tensorboard.html.80fc9efd.js
+1 −0 dist/assets/tools.html.21a62354.js
+1 −0 dist/assets/tools.html.8b8a44b2.js
+4 −4 dist/dreambooth/index.html
+4 −4 dist/index.html
+23 −23 dist/lora/basic.html
+4 −4 dist/lora/index.html
+63 −62 dist/lora/master.html
+4 −4 dist/lora/params.html
+34 −0 dist/lora/tools.html
+4 −4 dist/other/about.html
+6 −6 dist/other/settings.html
+11 −11 dist/tagger.html
+33 −0 dist/task.html
+4 −4 dist/tensorboard.html
26 changes: 23 additions & 3 deletions mikazuki/app.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import json
import os
import shlex
import subprocess
import sys
from datetime import datetime
from threading import Lock

import starlette.responses as starlette_responses
from fastapi import BackgroundTasks, FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles

import mikazuki.utils as utils
import toml

from mikazuki.models import TaggerInterrogateRequest
from mikazuki.tagger.interrogator import available_interrogators, on_interrogate
from mikazuki.tagger.interrogator import (available_interrogators,
on_interrogate)

app = FastAPI()
lock = Lock()

avaliable_scripts = [
"networks/extract_lora_from_models.py",
"networks/extract_lora_from_dylora.py"
]
# fix mimetype error in some fucking systems
_origin_guess_type = starlette_responses.guess_type

Expand Down Expand Up @@ -79,6 +85,19 @@ async def create_toml_file(request: Request, background_tasks: BackgroundTasks):
return {"status": "success"}


@app.post("/api/run_script")
async def run_script(request: Request, background_tasks: BackgroundTasks):
paras = await request.body()
j = json.loads(paras.decode("utf-8"))
script_name = j["script_name"]
if script_name not in avaliable_scripts:
return {"status": "fail"}
del j["script_name"]
cmd = script_name + ' ' + ' '.join(f'--{k} {v}' for k, v in j.items())
background_tasks.add_task(utils.run, cmd)
return {"status": "success"}


@app.post("/api/interrogate")
async def run_interrogate(req: TaggerInterrogateRequest, background_tasks: BackgroundTasks):
interrogator = available_interrogators.get(req.interrogator_model, available_interrogators["wd14-convnextv2-v2"])
Expand Down Expand Up @@ -111,3 +130,4 @@ async def index():


app.mount("/", StaticFiles(directory="frontend/dist"), name="static")

12 changes: 9 additions & 3 deletions mikazuki/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import subprocess
import importlib.util
from typing import Optional

python_bin = sys.executable

Expand All @@ -15,20 +16,25 @@ def is_installed(package):
return spec is not None


def run(command, desc=None, errdesc=None, custom_env=None, live=False):
def run(command,
desc: Optional[str] = None,
errdesc: Optional[str] = None,
custom_env: Optional[list] = None,
live: Optional[bool] = True,
shell: Optional[bool] = False):
if desc is not None:
print(desc)

if live:
result = subprocess.run(command, shell=True, env=os.environ if custom_env is None else custom_env)
result = subprocess.run(command, shell=shell, env=os.environ if custom_env is None else custom_env)
if result.returncode != 0:
raise RuntimeError(f"""{errdesc or 'Error running command'}.
Command: {command}
Error code: {result.returncode}""")

return ""

result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, env=os.environ if custom_env is None else custom_env)

if result.returncode != 0:
message = f"""{errdesc or 'Error running command'}.
Expand Down

0 comments on commit 58ad041

Please sign in to comment.