wsj1995 commited on
Commit
dedae7a
·
1 Parent(s): 5e720dd

feat: try cache

Browse files
Files changed (1) hide show
  1. api.py +15 -16
api.py CHANGED
@@ -63,22 +63,21 @@ async def upload_file(userId: str, modelId: str, filename: str, file: UploadFile
63
  file_location_folder = os.path.join(UPLOAD_DIRECTORY,userId)
64
  file_location = os.path.join(file_location_folder, filename)
65
  os.makedirs(file_location_folder, exist_ok=True)
66
- # try:
67
- with open(file_location, "wb") as buffer:
68
- buffer.write(await file.read())
69
- callback(modelId,'UPLOADING')
70
- pathInRepo = f"{userId}/{filename}"
71
- huggingfaceApi = HfApi(token=HUGGINGFACE_API_TOKEN)
72
- huggingfaceApi.upload_file(
73
- path_or_fileobj=file_location,
74
- path_in_repo=pathInRepo,
75
- repo_id=REPO_ID,
76
- repo_type="model"
77
- )
78
- callback(modelId,'UPLOADED')
79
- # except Exception as e:
80
- # print(e)
81
- # callback(modelId,'FAIL')
82
  os.remove(file_location)
83
  return {'success': True, 'id': modelId}
84
 
 
63
  file_location_folder = os.path.join(UPLOAD_DIRECTORY,userId)
64
  file_location = os.path.join(file_location_folder, filename)
65
  os.makedirs(file_location_folder, exist_ok=True)
66
+ try:
67
+ with open(file_location, "wb") as buffer:
68
+ buffer.write(await file.read())
69
+ callback(modelId,'UPLOADING')
70
+ pathInRepo = f"{userId}/{filename}"
71
+ huggingfaceApi = HfApi(token=HUGGINGFACE_API_TOKEN)
72
+ huggingfaceApi.upload_file(
73
+ path_or_fileobj=file_location,
74
+ path_in_repo=pathInRepo,
75
+ repo_id=REPO_ID,
76
+ repo_type="model"
77
+ )
78
+ callback(modelId,'UPLOADED')
79
+ except Exception as e:
80
+ callback(modelId,'FAIL')
 
81
  os.remove(file_location)
82
  return {'success': True, 'id': modelId}
83