Spaces:
Sleeping
Sleeping
danial0203
commited on
Commit
•
5b5d184
1
Parent(s):
562d36e
Update app.py
Browse files
app.py
CHANGED
@@ -13,20 +13,26 @@ aws_secret_access_key = os.getenv('AWS_SECRET_KEY')
|
|
13 |
region_name = os.getenv('AWS_REGION')
|
14 |
s3_bucket = os.getenv('AWS_BUCKET')
|
15 |
|
16 |
-
s3fs
|
|
|
|
|
|
|
|
|
|
|
17 |
textract_client = boto3.client('textract', region_name=region_name)
|
18 |
|
19 |
def upload_file_to_s3(file_path, bucket, object_name=None):
|
20 |
if object_name is None:
|
21 |
object_name = os.path.basename(file_path)
|
22 |
try:
|
23 |
-
|
24 |
-
|
25 |
return object_name
|
26 |
except FileNotFoundError:
|
27 |
print("The file was not found")
|
28 |
return None
|
29 |
|
|
|
30 |
def process_image(file_path, s3_bucket, textract_client):
|
31 |
s3_object_key = upload_file_to_s3(file_path, s3_bucket)
|
32 |
if not s3_object_key:
|
|
|
13 |
region_name = os.getenv('AWS_REGION')
|
14 |
s3_bucket = os.getenv('AWS_BUCKET')
|
15 |
|
16 |
+
# Properly initialize s3fs with environment variables
|
17 |
+
s3 = s3fs.S3FileSystem(
|
18 |
+
key=os.getenv('AWS_ACCESS_KEY'),
|
19 |
+
secret=os.getenv('AWS_SECRET_KEY'),
|
20 |
+
client_kwargs={'region_name': os.getenv('AWS_REGION')}
|
21 |
+
)
|
22 |
textract_client = boto3.client('textract', region_name=region_name)
|
23 |
|
24 |
def upload_file_to_s3(file_path, bucket, object_name=None):
|
25 |
if object_name is None:
|
26 |
object_name = os.path.basename(file_path)
|
27 |
try:
|
28 |
+
s3_path = f"{bucket}/{object_name}"
|
29 |
+
s3.upload(file_path, s3_path)
|
30 |
return object_name
|
31 |
except FileNotFoundError:
|
32 |
print("The file was not found")
|
33 |
return None
|
34 |
|
35 |
+
|
36 |
def process_image(file_path, s3_bucket, textract_client):
|
37 |
s3_object_key = upload_file_to_s3(file_path, s3_bucket)
|
38 |
if not s3_object_key:
|