| 43 | |
| 44 | |
| 45 | def 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 | |
| 69 | if __name__ == "__main__": |