Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring + standalone api #328

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

graemeniedermayer
Copy link
Contributor

@graemeniedermayer graemeniedermayer commented Aug 28, 2023

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 #316.

  • It keeps the output of the api the same. (The current outputs still feels poorly structured)
  • it does break api inputs a little bit.
  • remove gradio imports from api directories.
  • because depthmap_api.py was so small it's contents are append to the end of depthmap.py

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 graemeniedermayer marked this pull request as ready for review August 28, 2023 07:12
@semjon00 semjon00 self-requested a review September 8, 2023 08:04
@graemeniedermayer
Copy link
Contributor Author

should I update this?

@semjon00
Copy link
Collaborator

semjon00 commented Nov 10, 2023

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
Copy link
Collaborator

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

@graemeniedermayer
Copy link
Contributor Author

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

@davidmartinrius
Copy link
Contributor

davidmartinrius commented Dec 1, 2023

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
Copy link
Collaborator

semjon00 commented Dec 1, 2023

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
Copy link
Contributor Author

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

@davidmartinrius
Copy link
Contributor

Hello! I created a new pull request in #378

I hope it fits to the project standard 😄

David Martin Rius

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants