Spaces:
Running on Zero
Running on Zero
Skip empty video kwargs for image-only inference
Browse files
app.py
CHANGED
|
@@ -65,6 +65,17 @@ def strip_reasoning_output(text: str) -> str:
|
|
| 65 |
return text
|
| 66 |
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
def ensure_model_loaded():
|
| 69 |
global _MODEL, _PROCESSOR
|
| 70 |
if _MODEL is not None and _PROCESSOR is not None:
|
|
@@ -155,9 +166,9 @@ def run_inference(
|
|
| 155 |
"return_tensors": "pt",
|
| 156 |
"padding": False,
|
| 157 |
}
|
| 158 |
-
if video_inputs
|
| 159 |
processor_kwargs["videos"] = video_inputs
|
| 160 |
-
|
| 161 |
|
| 162 |
inputs = processor(**processor_kwargs)
|
| 163 |
target_device = next(model.parameters()).device
|
|
|
|
| 65 |
return text
|
| 66 |
|
| 67 |
|
| 68 |
+
def clean_video_kwargs(video_kwargs: dict) -> dict:
|
| 69 |
+
cleaned = {}
|
| 70 |
+
for key, value in video_kwargs.items():
|
| 71 |
+
if value is None:
|
| 72 |
+
continue
|
| 73 |
+
if isinstance(value, list) and len(value) == 0:
|
| 74 |
+
continue
|
| 75 |
+
cleaned[key] = value
|
| 76 |
+
return cleaned
|
| 77 |
+
|
| 78 |
+
|
| 79 |
def ensure_model_loaded():
|
| 80 |
global _MODEL, _PROCESSOR
|
| 81 |
if _MODEL is not None and _PROCESSOR is not None:
|
|
|
|
| 166 |
"return_tensors": "pt",
|
| 167 |
"padding": False,
|
| 168 |
}
|
| 169 |
+
if video_inputs:
|
| 170 |
processor_kwargs["videos"] = video_inputs
|
| 171 |
+
processor_kwargs.update(clean_video_kwargs(video_kwargs))
|
| 172 |
|
| 173 |
inputs = processor(**processor_kwargs)
|
| 174 |
target_device = next(model.parameters()).device
|