| from pathlib import Path |
| from typing import Any |
|
|
|
|
| def resolve_uploaded_path(uploaded: Any) -> Path: |
| if isinstance(uploaded, Path): |
| return uploaded |
| if isinstance(uploaded, str): |
| return Path(uploaded) |
| if isinstance(uploaded, dict): |
| for key in ("path", "orig_name", "name"): |
| value = uploaded.get(key) |
| if isinstance(value, str) and value: |
| return Path(value) |
| raise TypeError( |
| f"Unsupported uploaded file payload: expected path-like value or Gradio file dict, got {type(uploaded).__name__}" |
| ) |
|
|
|
|
| def resolve_uploaded_name(uploaded: Any) -> str: |
| if isinstance(uploaded, Path): |
| return uploaded.name |
| if isinstance(uploaded, str): |
| return Path(uploaded).name |
| if isinstance(uploaded, dict): |
| for key in ("orig_name", "name"): |
| value = uploaded.get(key) |
| if isinstance(value, str) and value: |
| return Path(value).name |
| path_value = uploaded.get("path") |
| if isinstance(path_value, str) and path_value: |
| return Path(path_value).name |
| raise TypeError( |
| f"Unsupported uploaded file payload: expected path-like value or Gradio file dict, got {type(uploaded).__name__}" |
| ) |
|
|