thygate / stable-diffusion-webui-depthmap-script

High Resolution Depth Maps for Stable Diffusion WebUI
MIT License
1.72k stars 159 forks source link

refactoring + standalone api #328

Open graemeniedermayer opened 1 year ago

graemeniedermayer commented 1 year ago

This pull request enables api to work with in standalone mode (the auto-generated docs are still wrong).


Notes

This implements many suggestions/changes from @semjon00 . I'm not entirely sure how @semjon00 should be credited.

Some of the alterations from the draft https://github.com/thygate/stable-diffusion-webui-depthmap-script/pull/316.

I have only tested it with core features. So things like 3d/video are unlikely to function.


How to use

The standalone api will be enabled with the options --api. The full start-up becomes python main.py --api.

sample api request (python 3.8)

import requests
from io import BytesIO
import base64
from PIL import Image
import json

with open("test_img.png", "rb") as image_file:
        img = base64.b64encode(image_file.read())

dics = {
  "input_images": [img],
  "generate_options":{
    "compute_device": "GPU",
    "model_type": "zoedepth_n (indoor)",
    "net_width": 512,
    "net_height": 512,
    "net_size_match": False,
    "boost": False,
    "invert_depth": False
  }
}

# this points to auto1111. this is usually the default local address.
url = 'http://127.0.0.1:7860/depth/generate'

#This is where the request is made
x = requests.post(url, json = dics)
print(x.text)
img = json.loads(x.text)['images'][0]
print(img)
#Image is decoded here. this might have changed in python 3.9
img_io = BytesIO(base64.b64decode(img))
im = Image.open(img_io)

#Image is
im.save('image1.png', 'PNG')
graemeniedermayer commented 1 year ago

should I update this?

semjon00 commented 1 year ago

Hi 😅 I got quite busy and could not really give much time to this. I am sorry.

My concern is breaking inputs - could you please try to do it so that there is no change? If API behaves exactly the same, but can be accessed without Gradio (and code is reasonable) - it would be a bliss and easy to merge.

semjon00 commented 1 year ago

Really would be nice to have it. People tell that API it is useful (for example aulerius)

graemeniedermayer commented 1 year ago

Things have been soo busy recently! I'll keep the API input the same.

davidmartinrius commented 11 months ago

Hi, how are you doing? This code is right, but if accepted maybe it will be deprecated soon as there is a project dedicated for the stable diffusion API: https://github.com/mix1009/sdwebuiapi

I am a contributor of that project and I am working in an endpoint to do the same task with depthmap script.

Also I added a new funcionality to generate videos with this project, without affecting the core.

Soon there will be a new pull request to this project and sdwebuiapi.

I added a new option RUN_MAKEVIDEO_API with parameters such as num of frames, fps, xyz movements, etc

Thank you!

David Martin Rius

semjon00 commented 11 months ago

Hello @davidmartinrius, nice to see you here! Honestly, I am even more busy with stuff nowadays, but I am looking forward for your MR, hope I can go through it quickly-enough 🤞🫠

graemeniedermayer commented 11 months ago

@davidmartinrius This sounds great! I was unaware of this repo thanks for linking it.

davidmartinrius commented 11 months ago

Hello! I created a new pull request in https://github.com/thygate/stable-diffusion-webui-depthmap-script/pull/378

I hope it fits to the project standard 😄

David Martin Rius