DavisEdward commited on
Commit
2201ca7
·
1 Parent(s): df4b4c7

Update file path extraction for Gradio 5.x objects

Browse files

Replaces 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.

Files changed (1) hide show
  1. 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 NamedString: str(obj) gives the path
45
- # Check if converting to string gives a valid path
46
- str_val = str(file_obj)
47
- if str_val and len(str_val) > 5 and ('/' in str_val or '\\' in str_val):
48
- return str_val
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