3030from paddle import __version__
3131from requests import HTTPError
3232
33- from .aistudio_hub_download import (
34- aistudio_hub_download ,
35- aistudio_hub_file_exists ,
36- aistudio_hub_try_to_load_from_cache ,
37- )
3833from .bos_download import bos_download , bos_file_exists , bos_try_to_load_from_cache
3934
4035
@@ -146,8 +141,8 @@ def resolve_file_path(
146141
147142 # check cache
148143 for filename in filenames :
149- cache_file_name = bos_aistudio_hf_try_to_load_from_cache (
150- repo_id , filename , cache_dir , subfolder , revision , repo_type , from_bos , from_aistudio , from_hf_hub
144+ cache_file_name = bos_hf_try_to_load_from_cache (
145+ repo_id , filename , cache_dir , subfolder , revision , repo_type , from_bos , from_hf_hub
151146 )
152147 if from_hf_hub and cache_file_name is _CACHED_NO_EXIST :
153148 cache_file_name = None
@@ -187,32 +182,25 @@ def resolve_file_path(
187182 return None
188183
189184 elif from_aistudio :
190- log_endpoint = "Aistudio Hub"
191- for filename in filenames :
192- download_kwargs ["filename" ] = filename
193- is_available = bos_aistudio_hf_file_exist (
194- repo_id ,
195- filename ,
196- subfolder = subfolder ,
197- repo_type = repo_type ,
198- revision = revision ,
199- token = token ,
200- endpoint = endpoint ,
201- from_bos = from_bos ,
202- from_aistudio = from_aistudio ,
203- from_hf_hub = from_hf_hub ,
204- )
205- if is_available :
206- cached_file = aistudio_hub_download (
207- ** download_kwargs ,
185+ for index , filename in enumerate (filenames ):
186+ try :
187+ from aistudio_sdk .file_download import (
188+ model_file_download as aistudio_download ,
208189 )
209- if cached_file is not None :
210- return cached_file
190+
191+ return aistudio_download (repo_id , filename , revision , local_files_only , local_dir )
192+ except Exception :
193+ if index < len (filenames ) - 1 :
194+ continue
195+ else :
196+ print (f"please make sure one of the { filenames } under the repo { repo_id } " )
197+ return None
198+
211199 elif from_hf_hub :
212200 log_endpoint = "Huggingface Hub"
213201 for filename in filenames :
214202 download_kwargs ["filename" ] = filename
215- is_available = bos_aistudio_hf_file_exist (
203+ is_available = bos_hf_file_exist (
216204 repo_id ,
217205 filename ,
218206 subfolder = subfolder ,
@@ -221,7 +209,6 @@ def resolve_file_path(
221209 token = token ,
222210 endpoint = endpoint ,
223211 from_bos = from_bos ,
224- from_aistudio = from_aistudio ,
225212 from_hf_hub = from_hf_hub ,
226213 )
227214 if is_available :
@@ -235,7 +222,7 @@ def resolve_file_path(
235222 download_kwargs ["url" ] = url
236223 for filename in filenames :
237224 download_kwargs ["filename" ] = filename
238- is_available = bos_aistudio_hf_file_exist (
225+ is_available = bos_hf_file_exist (
239226 repo_id ,
240227 filename ,
241228 subfolder = subfolder ,
@@ -244,7 +231,6 @@ def resolve_file_path(
244231 token = token ,
245232 endpoint = endpoint ,
246233 from_bos = from_bos ,
247- from_aistudio = from_aistudio ,
248234 from_hf_hub = from_hf_hub ,
249235 )
250236 if is_available :
@@ -291,7 +277,7 @@ def resolve_file_path(
291277 )
292278
293279
294- def bos_aistudio_hf_file_exist (
280+ def bos_hf_file_exist (
295281 repo_id : str ,
296282 filename : str ,
297283 * ,
@@ -301,7 +287,6 @@ def bos_aistudio_hf_file_exist(
301287 token : Optional [str ] = None ,
302288 endpoint : Optional [str ] = None ,
303289 from_bos : bool = True ,
304- from_aistudio : bool = False ,
305290 from_hf_hub : bool = False ,
306291):
307292 assert repo_id is not None , "repo_id cannot be None"
@@ -310,16 +295,7 @@ def bos_aistudio_hf_file_exist(
310295 if subfolder is None :
311296 subfolder = ""
312297 filename = os .path .join (subfolder , filename )
313- if from_aistudio :
314- out = aistudio_hub_file_exists (
315- repo_id = repo_id ,
316- filename = filename ,
317- repo_type = repo_type ,
318- revision = revision ,
319- token = token ,
320- endpoint = endpoint ,
321- )
322- elif from_hf_hub :
298+ if from_hf_hub :
323299 out = hf_hub_file_exists (
324300 repo_id = repo_id ,
325301 filename = filename ,
@@ -339,15 +315,14 @@ def bos_aistudio_hf_file_exist(
339315 return out
340316
341317
342- def bos_aistudio_hf_try_to_load_from_cache (
318+ def bos_hf_try_to_load_from_cache (
343319 repo_id : str ,
344320 filename : str ,
345321 cache_dir : Union [str , Path , None ] = None ,
346322 subfolder : str = None ,
347323 revision : Optional [str ] = None ,
348324 repo_type : Optional [str ] = None ,
349325 from_bos : bool = True ,
350- from_aistudio : bool = False ,
351326 from_hf_hub : bool = False ,
352327):
353328 if subfolder is None :
@@ -359,9 +334,7 @@ def bos_aistudio_hf_try_to_load_from_cache(
359334 revision = revision ,
360335 repo_type = repo_type ,
361336 )
362- if from_aistudio :
363- return aistudio_hub_try_to_load_from_cache (** load_kwargs )
364- elif from_hf_hub :
337+ if from_hf_hub :
365338 return hf_hub_try_to_load_from_cache (** load_kwargs )
366339 else :
367340 return bos_try_to_load_from_cache (** load_kwargs )
0 commit comments