Skip to content

Commit

Permalink
sync config functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythongor committed Jun 23, 2023
1 parent e0211c2 commit e77b6d6
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 21 deletions.
8 changes: 5 additions & 3 deletions README_Web.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ All this data is sent to ControlNet API when you request image generation.

This is main control panel of this app. Here are:

- `Brush customizer`. It handles behavior of drawing brush. Here you can change width, switch eraser, toggle shape modes and their filling. There is four shape modes: `pencil`, `line`, `ellipse` and `rectangle`.
- `Brush customizer` section. It handles behavior of drawing brush. Here you can change width, switch eraser, toggle shape modes and their filling. There is four shape modes: `pencil`, `line`, `ellipse` and `rectangle`.
- `Download` button. Downloads result image (if any).
- `Load config` button. Loads `controlnet.json` data to form fields.
- `Save config` button. Saves data from form fields to `controlnet.json`.
- `Clear` button. Resets `painting canvas`
- `Download` button. Downloads result image (if any)
- `Instant mode` button. Switches instant mode (requests image redraw just when you stroke)
- `Zen mode` button. Enters simplified interface mode
- `Generate` button. Triggers ControlNet API image generation.
Expand Down Expand Up @@ -98,7 +100,7 @@ Zen mode is more simplified interface mode. Only `painting canvas` and `result a

Pull requests are welcome. Development brunch is https://github.com/Pythongor/SdPaint/tree/web-view.

To run in development mode first you need to install `npm`. If you're done with it run `StartWeb.bat` or `start-web.sh` depending on your OS. There can be alert, ignore it. In separated terminal run `cd scripts\views\WebView; npm start` from project root. Your default browser will open http://localhost:3000/ with app. Now all your changes in `scripts\views\WebView\src` will renew page.
To run in development mode first you need to install `npm`. If you're done with it run `StartWeb.bat` or `start-web.sh` depending on your OS. There can be alert, ignore it. In separated terminal run `cd scripts\views\WebView; npm install` then `npm start` from project root. Your default browser will open http://localhost:3000/ with app. Now all your changes in `scripts\views\WebView\src` will renew page.

## License

Expand Down
Binary file modified images/web_tools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 18 additions & 4 deletions scripts/views/WebView/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


import json
import os
import base64
Expand Down Expand Up @@ -40,8 +39,6 @@ def send_request():
global sd_image
response = post_request(state)
if response["status_code"] == 200:
print(response.keys(), response["status_code"], response.get(
"image", None)[:10])
if response.get("image", None):
sd_image = response["image"]
# elif response.get("batch_images", None):
Expand All @@ -51,10 +48,27 @@ def send_request():

@app.get('/config')
async def root():
with open('../controlnet.json', 'r') as f:
with open('./controlnet.json', 'r') as f:
return json.load(f)


@app.post('/config')
async def root(data: Request):
data = await data.json()
with open('./controlnet.json', 'r') as f:
json_data = json.load(f)
json_data["prompt"] = data["prompt"]
json_data["negative_prompt"] = data["negative_prompt"]
json_data["seed"] = data["seed"]
json_data["steps"] = data["steps"]
json_data["cfg_scale"] = data["cfg_scale"]
json_data["batch_size"] = data["batch_size"]
json_data["controlnet_units"][0]["module"] = data["module"]
json_data["controlnet_units"][0]["model"] = data["model"]
with open('./controlnet.json', 'w') as f:
f.write(json.dumps(json_data, indent=4))


@app.get('/models')
async def root():
return state.control_net["controlnet_models"]
Expand Down
12 changes: 6 additions & 6 deletions scripts/views/WebView/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"files": {
"main.css": "./static/css/main.d055145b.css",
"main.js": "./static/js/main.113b3046.js",
"main.css": "./static/css/main.c9f52137.css",
"main.js": "./static/js/main.3221a851.js",
"index.html": "./index.html",
"main.d055145b.css.map": "./static/css/main.d055145b.css.map",
"main.113b3046.js.map": "./static/js/main.113b3046.js.map"
"main.c9f52137.css.map": "./static/css/main.c9f52137.css.map",
"main.3221a851.js.map": "./static/js/main.3221a851.js.map"
},
"entrypoints": [
"static/css/main.d055145b.css",
"static/js/main.113b3046.js"
"static/css/main.c9f52137.css",
"static/js/main.3221a851.js"
]
}
2 changes: 1 addition & 1 deletion scripts/views/WebView/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="SdPaint - Painting with Stable Diffusion"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><title>SdPaint</title><script defer="defer" src="./static/js/main.7d47d93e.js"></script><link href="./static/css/main.b3a82c52.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="SdPaint - Painting with Stable Diffusion"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><title>SdPaint</title><script defer="defer" src="./static/js/main.3221a851.js"></script><link href="./static/css/main.c9f52137.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
2 changes: 0 additions & 2 deletions scripts/views/WebView/build/static/css/main.b3a82c52.css

This file was deleted.

Loading

0 comments on commit e77b6d6

Please sign in to comment.