Spaces:
Runtime error
Runtime error
VikramSingh178
commited on
Commit
β’
fed5666
1
Parent(s):
3f1c16e
chore: Update S3ManagerService to use settings from config_settings.py
Browse files- api/routers/painting.py +1 -1
- config_settings.py +1 -1
- scripts/s3_manager.py +8 -8
api/routers/painting.py
CHANGED
@@ -17,7 +17,7 @@ pl.seed_everything(42)
|
|
17 |
router = APIRouter()
|
18 |
|
19 |
# Initialize Hydra configuration
|
20 |
-
with initialize(version_base=None, config_path=
|
21 |
cfg = compose(config_name="inpainting")
|
22 |
|
23 |
# Load the inpainting pipeline
|
|
|
17 |
router = APIRouter()
|
18 |
|
19 |
# Initialize Hydra configuration
|
20 |
+
with initialize(version_base=None, config_path="../../configs"):
|
21 |
cfg = compose(config_name="inpainting")
|
22 |
|
23 |
# Load the inpainting pipeline
|
config_settings.py
CHANGED
@@ -8,5 +8,5 @@ class Settings(BaseSettings):
|
|
8 |
|
9 |
|
10 |
|
11 |
-
Settings()
|
12 |
|
|
|
8 |
|
9 |
|
10 |
|
11 |
+
settings = Settings()
|
12 |
|
scripts/s3_manager.py
CHANGED
@@ -5,25 +5,25 @@ import boto3
|
|
5 |
from botocore.config import Config
|
6 |
import random
|
7 |
import string
|
8 |
-
from
|
|
|
|
|
9 |
|
10 |
-
# Load environment variables from the .env file
|
11 |
-
load_dotenv('../config.env')
|
12 |
|
13 |
class S3ManagerService:
|
14 |
def __init__(self):
|
15 |
self.s3 = boto3.client(
|
16 |
"s3",
|
17 |
config=Config(signature_version="s3v4"),
|
18 |
-
aws_access_key_id=
|
19 |
-
aws_secret_access_key=
|
20 |
-
region_name=
|
21 |
)
|
22 |
|
23 |
def generate_signed_url(self, file_name: str, exp: int = 43200) -> str: # 43200 seconds = 12 hours
|
24 |
return self.s3.generate_presigned_url(
|
25 |
"get_object",
|
26 |
-
Params={"Bucket":
|
27 |
ExpiresIn=exp,
|
28 |
)
|
29 |
|
@@ -36,7 +36,7 @@ class S3ManagerService:
|
|
36 |
return f"{file_real_name}-{random_string}.{file_extension}"
|
37 |
|
38 |
def upload_file(self, file, file_name) -> str:
|
39 |
-
self.s3.upload_fileobj(file,
|
40 |
return file_name
|
41 |
|
42 |
def upload_base64_file(self, base64_file: str, file_name: str) -> str:
|
|
|
5 |
from botocore.config import Config
|
6 |
import random
|
7 |
import string
|
8 |
+
from config_settings import settings
|
9 |
+
|
10 |
+
|
11 |
|
|
|
|
|
12 |
|
13 |
class S3ManagerService:
|
14 |
def __init__(self):
|
15 |
self.s3 = boto3.client(
|
16 |
"s3",
|
17 |
config=Config(signature_version="s3v4"),
|
18 |
+
aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
|
19 |
+
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
|
20 |
+
region_name=settings.AWS_REGION,
|
21 |
)
|
22 |
|
23 |
def generate_signed_url(self, file_name: str, exp: int = 43200) -> str: # 43200 seconds = 12 hours
|
24 |
return self.s3.generate_presigned_url(
|
25 |
"get_object",
|
26 |
+
Params={"Bucket": settings.AWS_BUCKET_NAME, "Key": file_name},
|
27 |
ExpiresIn=exp,
|
28 |
)
|
29 |
|
|
|
36 |
return f"{file_real_name}-{random_string}.{file_extension}"
|
37 |
|
38 |
def upload_file(self, file, file_name) -> str:
|
39 |
+
self.s3.upload_fileobj(file, settings.AWS_BUCKET_NAME, file_name)
|
40 |
return file_name
|
41 |
|
42 |
def upload_base64_file(self, base64_file: str, file_name: str) -> str:
|