(
depth_input_images: List[str] = Body([], title='Input Images'),
options: Dict[str, object] = Body("options", title='Generation options'),
)
| 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, |
| 100 | 'depth_anything_v2_small': 12, |
| 101 | 'depth_anything_v2_base': 13, |
| 102 | 'depth_anything_v2_large': 14 |
| 103 | } |
| 104 | |
| 105 | model_type = options["model_type"] |
| 106 | |
| 107 | model_id = None |
| 108 | if isinstance(model_type, str): |
| 109 | # Check if the string is in the available_models dictionary |
| 110 | if model_type in available_models: |
| 111 | model_id = available_models[model_type] |
| 112 | else: |
| 113 | available_strings = list(available_models.keys()) |
| 114 | raise HTTPException(status_code=400, detail={'error': 'Invalid model string', 'available_models': available_strings}) |
| 115 | elif isinstance(model_type, int): |
| 116 | model_id = model_type |
| 117 | else: |
| 118 | raise HTTPException(status_code=400, detail={'error': 'Invalid model parameter type'}) |
| 119 | |
| 120 | options["model_type"] = model_id |
| 121 | |
| 122 | video_parameters = options["video_parameters"] |
| 123 | |
| 124 | required_params = ["vid_numframes", "vid_fps", "vid_traj", "vid_shift", "vid_border", "dolly", "vid_format", "vid_ssaa", "output_filename"] |
| 125 | |
| 126 | missing_params = [param for param in required_params if param not in video_parameters] |
| 127 | |
| 128 | if missing_params: |
| 129 | raise HTTPException(status_code=400, detail={'error': f"Missing required parameter(s): {', '.join(missing_params)}"}) |
| 130 | |
| 131 | vid_numframes = video_parameters["vid_numframes"] |
| 132 | vid_fps = video_parameters["vid_fps"] |
| 133 | vid_traj = video_parameters["vid_traj"] |
| 134 | vid_shift = video_parameters["vid_shift"] |
| 135 | vid_border = video_parameters["vid_border"] |
nothing calls this directly
no test coverage detected