@@ -101,27 +101,31 @@ async def unload(self):
101101
102102class File (BaseModel ):
103103 """A class representing a file in the inference.sh ecosystem."""
104- path : str # Absolute path to the file or URL
104+ uri : str # Original location (URL or file path)
105+ path : Optional [str ] = None # Resolved local file path
105106 mime_type : Optional [str ] = None # MIME type of the file
106107 size : Optional [int ] = None # File size in bytes
107108 filename : Optional [str ] = None # Original filename if available
108- _tmp_path : Optional [str ] = None # Internal storage for temporary file path
109+ _tmp_path : Optional [str ] = PrivateAttr ( default = None ) # Internal storage for temporary file path
109110
110111 def __init__ (self , ** data ):
111112 super ().__init__ (** data )
112- if self ._is_url (self .path ):
113+ if self ._is_url (self .uri ):
113114 self ._download_url ()
114- elif not os .path .isabs (self .path ):
115- self .path = os .path .abspath (self .path )
115+ elif not os .path .isabs (self .uri ):
116+ self .path = os .path .abspath (self .uri )
117+ else :
118+ self .path = self .uri
116119 self ._populate_metadata ()
117120
118121 def _is_url (self , path : str ) -> bool :
119122 """Check if the path is a URL."""
120123 parsed = urllib .parse .urlparse (path )
121124 return parsed .scheme in ('http' , 'https' )
125+
122126 def _download_url (self ) -> None :
123127 """Download the URL to a temporary file and update the path."""
124- original_url = self .path
128+ original_url = self .uri
125129 tmp_file = None
126130 try :
127131 # Create a temporary file with a suffix based on the URL path
@@ -179,7 +183,7 @@ def _populate_metadata(self) -> None:
179183 @classmethod
180184 def from_path (cls , path : Union [str , os .PathLike ]) -> 'File' :
181185 """Create a File instance from a file path."""
182- return cls (path = str (path ))
186+ return cls (uri = str (path ))
183187
184188 def _guess_mime_type (self ) -> Optional [str ]:
185189 """Guess the MIME type of the file."""
0 commit comments