mirror of
https://github.com/vladmandic/automatic
synced 2026-09-09 14:28:43 +02:00
rename
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import base64
|
||||
import logging
|
||||
import requests
|
||||
from PIL import Image
|
||||
|
||||
sd_url = os.environ.get('SDAPI_URL', "http://127.0.0.1:7860")
|
||||
sd_username = os.environ.get('SDAPI_USR', None)
|
||||
sd_password = os.environ.get('SDAPI_PWD', None)
|
||||
|
||||
logging.basicConfig(level = logging.INFO, format = '%(asctime)s %(levelname)s: %(message)s')
|
||||
log = logging.getLogger(__name__)
|
||||
sd_url = "http://127.0.0.1:7860"
|
||||
model = None # "meina-unreal-v30"
|
||||
|
||||
filename='/tmp/simple-txt2img.jpg'
|
||||
model = None # desired model name, will be set if not none
|
||||
options = {
|
||||
"prompt": "city at night",
|
||||
"negative_prompt": "foggy, blurry",
|
||||
@@ -25,13 +31,20 @@ options = {
|
||||
"send_images": True,
|
||||
}
|
||||
|
||||
def auth():
|
||||
if sd_username is not None and sd_password is not None:
|
||||
return requests.auth.HTTPBasicAuth(sd_username, sd_password)
|
||||
return None
|
||||
|
||||
|
||||
def post(endpoint: str, dct: dict = None):
|
||||
req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300)
|
||||
req = requests.post(f'{sd_url}{endpoint}', json = dct, timeout=300, verify=False, auth=auth())
|
||||
if req.status_code != 200:
|
||||
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url }
|
||||
else:
|
||||
return req.json()
|
||||
|
||||
|
||||
def generate(num: int = 0):
|
||||
log.info(f'sending generate request: {num+1} {options}')
|
||||
if model is not None:
|
||||
@@ -42,10 +55,12 @@ def generate(num: int = 0):
|
||||
for i in range(len(data['images'])):
|
||||
b64 = data['images'][i].split(',',1)[0]
|
||||
image = Image.open(io.BytesIO(base64.b64decode(b64)))
|
||||
log.info(f'received image: {image.size}')
|
||||
image.save(filename)
|
||||
log.info(f'received image: size={image.size} file={filename}')
|
||||
else:
|
||||
log.warning(f'no images received: {data}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.argv.pop(0)
|
||||
repeats = int(''.join(sys.argv) or '1')
|
||||
Submodule extensions-builtin/sd-webui-agent-scheduler updated: e9056ee69c...1bb04d1fbe
+2
-2
@@ -892,8 +892,8 @@ def restart_server(restart=True):
|
||||
demo.server.close()
|
||||
demo.fns = []
|
||||
# os._exit(0)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
log.error(f'Server shutdown error: {e}')
|
||||
if restart:
|
||||
log.info('Server will restart')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user