Hjgugugjhuhjggg commited on
Commit
e619e74
·
verified ·
1 Parent(s): d594fbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -5
app.py CHANGED
@@ -12,12 +12,11 @@ import soundfile as sf
12
  import numpy as np
13
  from fastapi import FastAPI, HTTPException, Request, UploadFile, File
14
  from fastapi.responses import StreamingResponse
15
- from pydantic import BaseModel, ValidationError, field_validator
16
  from transformers import (
17
  AutoConfig,
18
  AutoModelForCausalLM,
19
  AutoTokenizer,
20
- pipeline,
21
  GenerationConfig,
22
  StoppingCriteriaList
23
  )
@@ -110,7 +109,7 @@ class S3ModelLoader:
110
  def download_model_from_huggingface(self, model_name):
111
  try:
112
  logging.info(f"Downloading model {model_name} from Hugging Face...")
113
- model_dir = hf_hub_download(model_name, token=HUGGINGFACE_HUB_TOKEN)
114
  self.s3_client.upload_file(model_dir, self.bucket_name, f"lilmeaty_garca/{model_name}")
115
  logging.info(f"Model {model_name} saved to S3 successfully.")
116
  except Exception as e:
@@ -222,8 +221,6 @@ async def generate(request: Request, body: GenerateRequest):
222
 
223
  except HTTPException as e:
224
  raise e
225
- except ValidationError as e:
226
- raise HTTPException(status_code=422, detail=e.errors())
227
  except Exception as e:
228
  logging.exception(f"An unexpected error occurred: {e}")
229
  raise HTTPException(status_code=500, detail="An unexpected error occurred.")
 
12
  import numpy as np
13
  from fastapi import FastAPI, HTTPException, Request, UploadFile, File
14
  from fastapi.responses import StreamingResponse
15
+ from pydantic import BaseModel, field_validator
16
  from transformers import (
17
  AutoConfig,
18
  AutoModelForCausalLM,
19
  AutoTokenizer,
 
20
  GenerationConfig,
21
  StoppingCriteriaList
22
  )
 
109
  def download_model_from_huggingface(self, model_name):
110
  try:
111
  logging.info(f"Downloading model {model_name} from Hugging Face...")
112
+ model_dir = hf_hub_download(model_name, token=HUGGINGFACE_HUB_TOKEN, filename=model_name.split('/')[-1])
113
  self.s3_client.upload_file(model_dir, self.bucket_name, f"lilmeaty_garca/{model_name}")
114
  logging.info(f"Model {model_name} saved to S3 successfully.")
115
  except Exception as e:
 
221
 
222
  except HTTPException as e:
223
  raise e
 
 
224
  except Exception as e:
225
  logging.exception(f"An unexpected error occurred: {e}")
226
  raise HTTPException(status_code=500, detail="An unexpected error occurred.")