MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / depth_api

Function depth_api

scripts/depthmap_api.py:42–177  ·  view source on GitHub ↗
(_: gr.Blocks, app: FastAPI)

Source from the content-addressed store, hash-verified

40
41
42def depth_api(_: gr.Blocks, app: FastAPI):
43 @app.get("/depth/version")
44 async def version():
45 return {"version": SCRIPT_VERSION}
46
47 @app.get("/depth/get_options")
48 async def get_options():
49 return {"options": sorted([x.name.lower() for x in go])}
50
51 # TODO: some potential inputs not supported (like custom depthmaps)
52 @app.post("/depth/generate")
53 async def process(
54 depth_input_images: List[str] = Body([], title='Input Images'),
55 options: Dict[str, object] = Body("options", title='Generation options'),
56 ):
57 # TODO: restrict mesh options
58
59 if len(depth_input_images) == 0:
60 raise HTTPException(status_code=422, detail="No images supplied")
61 print(f"Processing {str(len(depth_input_images))} images trough the API")
62
63 pil_images = []
64 for input_image in depth_input_images:
65 pil_images.append(to_base64_PIL(input_image))
66 outpath = backbone.get_outpath()
67 gen_obj = core_generation_funnel(outpath, pil_images, None, None, options)
68
69 results_based = []
70 for count, type, result in gen_obj:
71 if not isinstance(result, Image.Image):
72 continue
73 results_based += [encode_to_base64(result)]
74
75 return {"images": results_based, "info": "Success"}
76
77 @app.post("/depth/generate/video")
78 async def process_video(
79 depth_input_images: List[str] = Body([], title='Input Images'),
80 options: Dict[str, object] = Body("options", title='Generation options'),
81 ):
82 if len(depth_input_images) == 0:
83 raise HTTPException(status_code=422, detail="No images supplied")
84 print(f"Processing {str(len(depth_input_images))} images trough the API")
85
86 # You can use either these strings, or integers
87 available_models = {
88 'res101': 0,
89 'dpt_beit_large_512': 1, #midas 3.1
90 'dpt_beit_large_384': 2, #midas 3.1
91 'dpt_large_384': 3, #midas 3.0
92 'dpt_hybrid_384': 4, #midas 3.0
93 'midas_v21': 5,
94 'midas_v21_small': 6,
95 'zoedepth_n': 7, #indoor
96 'zoedepth_k': 8, #outdoor
97 'zoedepth_nk': 9,
98 'marigold_v1': 10,
99 'depth_anything': 11,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected