akhaliq HF Staff commited on
Commit
ffd1a97
·
verified ·
1 Parent(s): e1950cc

Explicit gr.Request in api handlers (ZeroGPU token forwarding in Server mode)

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -4,6 +4,7 @@ from functools import partial
4
  from pathlib import Path
5
 
6
  import av
 
7
  import numpy as np
8
  import torch
9
  from fastapi.responses import HTMLResponse
@@ -134,8 +135,10 @@ app = Server(
134
 
135
 
136
  @app.api(name="predict_depth")
137
- def predict_depth(image: FileData) -> FileData:
138
  """Estimate metric depth for an uploaded photo; returns the colorized depth map."""
 
 
139
  img, f_px = load_rgb(image["path"]) # f_px: the focal length recorded in the photo, or None
140
  rgb = _infer_image(img, f_px)
141
  # Write beside the uploaded input: it is in Gradio's upload cache, which is servable; a raw
@@ -146,7 +149,7 @@ def predict_depth(image: FileData) -> FileData:
146
 
147
 
148
  @app.api(name="predict_depth_video")
149
- def predict_depth_video(video: FileData) -> FileData:
150
  """Estimate metric depth for an uploaded video (first 100 frames); returns the depth video."""
151
  return FileData(path=_infer_video(video["path"]))
152
 
 
4
  from pathlib import Path
5
 
6
  import av
7
+ import gradio as gr
8
  import numpy as np
9
  import torch
10
  from fastapi.responses import HTMLResponse
 
135
 
136
 
137
  @app.api(name="predict_depth")
138
+ def predict_depth(image: FileData, request: gr.Request) -> FileData:
139
  """Estimate metric depth for an uploaded photo; returns the colorized depth map."""
140
+ # request is taken explicitly: Server-mode ZeroGPU token forwarding is more reliable with it
141
+ # in the signature (see MiniMaxAI/MiniMax-H3-Turbo-Lora commit 7db57ff).
142
  img, f_px = load_rgb(image["path"]) # f_px: the focal length recorded in the photo, or None
143
  rgb = _infer_image(img, f_px)
144
  # Write beside the uploaded input: it is in Gradio's upload cache, which is servable; a raw
 
149
 
150
 
151
  @app.api(name="predict_depth_video")
152
+ def predict_depth_video(video: FileData, request: gr.Request) -> FileData:
153
  """Estimate metric depth for an uploaded video (first 100 frames); returns the depth video."""
154
  return FileData(path=_infer_video(video["path"]))
155