MCPcopy
hub / github.com/vladmandic/sdnext / info

Function info

cli/api-preprocess.py:45–66  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

43
44
45def info(args): # pylint: disable=redefined-outer-name
46 t0 = time.time()
47 with open(args.input, 'rb') as f:
48 content = f.read()
49 models = get('/sdapi/v1/preprocessors')
50 log.info(f'models: {models}')
51 req = {
52 'model': args.model or 'Canny',
53 'image': base64.b64encode(content).decode(),
54 'config': { 'low_threshold': 50 },
55 }
56 data = post('/sdapi/v1/preprocess', req)
57 t1 = time.time()
58 if 'image' in data:
59 b64 = data['image'].split(',',1)[0]
60 image = Image.open(io.BytesIO(base64.b64decode(b64)))
61 log.info(f'received image: size={image.size} time={t1-t0:.2f}')
62 if args.output:
63 image.save(args.output)
64 log.info(f'saved image: fn={args.output}')
65 else:
66 log.info(f'received: {data} time={t1-t0:.2f}')
67
68
69if __name__ == "__main__":

Callers 1

api-preprocess.pyFile · 0.70

Calls 6

infoMethod · 0.80
getFunction · 0.70
postFunction · 0.70
readMethod · 0.45
decodeMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected