wsj1995 commited on
Commit
272eeaf
·
1 Parent(s): 2d84c1c

fix: 去掉try

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