HimankJ commited on
Commit
d997b45
·
verified ·
1 Parent(s): 4e024ae

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +0 -1
  2. utils/model_loader.py +6 -24
README.md CHANGED
@@ -7,4 +7,3 @@ sdk_version: 5.21.0
7
 
8
  # Files to include
9
  .aws/
10
- .aws/
 
7
 
8
  # Files to include
9
  .aws/
 
utils/model_loader.py CHANGED
@@ -17,9 +17,6 @@ class ModelLoader:
17
  # Create directories if they don't exist
18
  os.makedirs('model', exist_ok=True)
19
 
20
- # Set AWS credentials path
21
- self.aws_credentials_path = self.get_aws_credentials_path()
22
-
23
  # Download and load model
24
  self.download_latest_model()
25
  self.model = self.load_model()
@@ -28,32 +25,17 @@ class ModelLoader:
28
  self.labels = self.get_labels()
29
  self.facts = self.get_facts()
30
 
31
- def get_aws_credentials_path(self):
32
- """Get the path to AWS credentials file"""
33
- # Check current directory first
34
- local_aws_dir = Path('.aws')
35
- if local_aws_dir.exists():
36
- return local_aws_dir
37
-
38
- # Check home directory next
39
- home_aws_dir = Path.home() / '.aws'
40
- if home_aws_dir.exists():
41
- return home_aws_dir
42
-
43
- raise FileNotFoundError("AWS credentials directory not found")
44
-
45
  def download_latest_model(self):
46
  """Download the latest model from S3"""
47
  try:
48
- # Create boto3 session with specific credentials file
49
- session = boto3.Session(
50
- profile_name='default',
51
- shared_credentials_file=str(self.aws_credentials_path / 'credentials')
 
 
52
  )
53
 
54
- # Create S3 client using the session
55
- s3 = session.client('s3')
56
-
57
  # Download the model
58
  s3.download_file(
59
  self.bucket_name,
 
17
  # Create directories if they don't exist
18
  os.makedirs('model', exist_ok=True)
19
 
 
 
 
20
  # Download and load model
21
  self.download_latest_model()
22
  self.model = self.load_model()
 
25
  self.labels = self.get_labels()
26
  self.facts = self.get_facts()
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def download_latest_model(self):
29
  """Download the latest model from S3"""
30
  try:
31
+ # Create S3 client using environment variables
32
+ s3 = boto3.client(
33
+ 's3',
34
+ aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'),
35
+ aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY'),
36
+ region_name=os.getenv('AWS_DEFAULT_REGION')
37
  )
38
 
 
 
 
39
  # Download the model
40
  s3.download_file(
41
  self.bucket_name,