Commit
·
2201ca7
1
Parent(s):
df4b4c7
Update file path extraction for Gradio 5.x objects
Browse filesReplaces string conversion with direct access to the .value attribute for Gradio 5.x file objects. Ensures compatibility with newer Gradio versions and improves reliability of file path extraction.
- gradio_demo.py +6 -6
gradio_demo.py
CHANGED
|
@@ -41,16 +41,16 @@ def get_file_path(file_obj) -> str:
|
|
| 41 |
if isinstance(file_obj, str):
|
| 42 |
return file_obj
|
| 43 |
|
| 44 |
-
# Gradio 5.x
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
# Gradio 3.x/4.x: object with .name attribute containing the path
|
| 51 |
if hasattr(file_obj, 'name'):
|
| 52 |
name_val = file_obj.name
|
| 53 |
-
if isinstance(name_val, str) and len(name_val) > 5:
|
| 54 |
return name_val
|
| 55 |
|
| 56 |
# Try .path attribute
|
|
|
|
| 41 |
if isinstance(file_obj, str):
|
| 42 |
return file_obj
|
| 43 |
|
| 44 |
+
# Gradio 5.x namespace object: path is in .value attribute
|
| 45 |
+
if hasattr(file_obj, 'value'):
|
| 46 |
+
value = file_obj.value
|
| 47 |
+
if isinstance(value, str) and len(value) > 5:
|
| 48 |
+
return value
|
| 49 |
|
| 50 |
# Gradio 3.x/4.x: object with .name attribute containing the path
|
| 51 |
if hasattr(file_obj, 'name'):
|
| 52 |
name_val = file_obj.name
|
| 53 |
+
if isinstance(name_val, str) and len(name_val) > 5 and '/' in name_val:
|
| 54 |
return name_val
|
| 55 |
|
| 56 |
# Try .path attribute
|