seanpedrickcase commited on
Commit
b8e245f
·
1 Parent(s): dc17f6e

Can now specify the root path that the app will run on with an environment variable

Browse files
Files changed (3) hide show
  1. app.py +6 -3
  2. tools/aws_functions.py +16 -14
  3. tools/redaction_review.py +1 -1
app.py CHANGED
@@ -396,7 +396,7 @@ with app:
396
  then(fn = upload_file_to_s3, inputs=[usage_logs_state, usage_s3_logs_loc_state], outputs=[s3_logs_output_textbox])
397
 
398
  # Get some environment variables and Launch the Gradio app
399
- COGNITO_AUTH = get_or_create_env_var('COGNITO_AUTH', '1')
400
  print(f'The value of COGNITO_AUTH is {COGNITO_AUTH}')
401
 
402
  RUN_DIRECT_MODE = get_or_create_env_var('RUN_DIRECT_MODE', '0')
@@ -411,14 +411,17 @@ print(f'The value of MAX_FILE_SIZE is {MAX_FILE_SIZE}')
411
  GRADIO_SERVER_PORT = int(get_or_create_env_var('GRADIO_SERVER_PORT', '7860'))
412
  print(f'The value of GRADIO_SERVER_PORT is {GRADIO_SERVER_PORT}')
413
 
 
 
 
414
  if __name__ == "__main__":
415
 
416
  if RUN_DIRECT_MODE == "0":
417
 
418
  if os.environ['COGNITO_AUTH'] == "1":
419
- app.queue(max_size=MAX_QUEUE_SIZE).launch(show_error=True, auth=authenticate_user, max_file_size=MAX_FILE_SIZE, server_port=GRADIO_SERVER_PORT)
420
  else:
421
- app.queue(max_size=MAX_QUEUE_SIZE).launch(show_error=True, inbrowser=True, max_file_size=MAX_FILE_SIZE, server_port=GRADIO_SERVER_PORT)
422
 
423
  else:
424
  from tools.cli_redact import main
 
396
  then(fn = upload_file_to_s3, inputs=[usage_logs_state, usage_s3_logs_loc_state], outputs=[s3_logs_output_textbox])
397
 
398
  # Get some environment variables and Launch the Gradio app
399
+ COGNITO_AUTH = get_or_create_env_var('COGNITO_AUTH', '0')
400
  print(f'The value of COGNITO_AUTH is {COGNITO_AUTH}')
401
 
402
  RUN_DIRECT_MODE = get_or_create_env_var('RUN_DIRECT_MODE', '0')
 
411
  GRADIO_SERVER_PORT = int(get_or_create_env_var('GRADIO_SERVER_PORT', '7860'))
412
  print(f'The value of GRADIO_SERVER_PORT is {GRADIO_SERVER_PORT}')
413
 
414
+ ROOT_PATH = get_or_create_env_var('ROOT_PATH', '')
415
+ print(f'The value of ROOT_PATH is {ROOT_PATH}')
416
+
417
  if __name__ == "__main__":
418
 
419
  if RUN_DIRECT_MODE == "0":
420
 
421
  if os.environ['COGNITO_AUTH'] == "1":
422
+ app.queue(max_size=MAX_QUEUE_SIZE).launch(show_error=True, auth=authenticate_user, max_file_size=MAX_FILE_SIZE, server_port=GRADIO_SERVER_PORT, root_path=ROOT_PATH)
423
  else:
424
+ app.queue(max_size=MAX_QUEUE_SIZE).launch(show_error=True, inbrowser=True, max_file_size=MAX_FILE_SIZE, server_port=GRADIO_SERVER_PORT, root_path=ROOT_PATH)
425
 
426
  else:
427
  from tools.cli_redact import main
tools/aws_functions.py CHANGED
@@ -19,25 +19,27 @@ print(f'The value of AWS_REGION is {AWS_REGION}')
19
 
20
 
21
  def get_assumed_role_info():
22
- sts_endpoint = 'https://sts.' + AWS_REGION + '.amazonaws.com'
23
- sts = boto3.client('sts', region_name=AWS_REGION, endpoint_url=sts_endpoint)
24
- response = sts.get_caller_identity()
25
-
26
- # Extract ARN of the assumed role
27
- assumed_role_arn = response['Arn']
28
-
29
- # Extract the name of the assumed role from the ARN
30
- assumed_role_name = assumed_role_arn.split('/')[-1]
31
-
32
- return assumed_role_arn, assumed_role_name
33
 
34
  if RUN_AWS_FUNCTIONS == "1":
35
  try:
36
  bucket_name = os.environ['DOCUMENT_REDACTION_BUCKET']
37
- session = boto3.Session()
 
 
38
 
39
  except Exception as e:
40
- print(e)
41
 
42
  try:
43
  assumed_role_arn, assumed_role_name = get_assumed_role_info()
@@ -46,7 +48,7 @@ if RUN_AWS_FUNCTIONS == "1":
46
  print("Assumed Role Name:", assumed_role_name)
47
 
48
  except Exception as e:
49
- print(e)
50
 
51
  # Download direct from S3 - requires login credentials
52
  def download_file_from_s3(bucket_name, key, local_file_path_and_name):
 
19
 
20
 
21
  def get_assumed_role_info():
22
+ sts_endpoint = 'https://sts.' + AWS_REGION + '.amazonaws.com'
23
+ sts = boto3.client('sts', region_name=AWS_REGION, endpoint_url=sts_endpoint)
24
+ response = sts.get_caller_identity()
25
+
26
+ # Extract ARN of the assumed role
27
+ assumed_role_arn = response['Arn']
28
+
29
+ # Extract the name of the assumed role from the ARN
30
+ assumed_role_name = assumed_role_arn.split('/')[-1]
31
+
32
+ return assumed_role_arn, assumed_role_name
33
 
34
  if RUN_AWS_FUNCTIONS == "1":
35
  try:
36
  bucket_name = os.environ['DOCUMENT_REDACTION_BUCKET']
37
+ session = boto3.Session()
38
+
39
+ print("session:", session)
40
 
41
  except Exception as e:
42
+ print("Could not start boto3 session:", e)
43
 
44
  try:
45
  assumed_role_arn, assumed_role_name = get_assumed_role_info()
 
48
  print("Assumed Role Name:", assumed_role_name)
49
 
50
  except Exception as e:
51
+ print("Could not get assumed role from STS:", e)
52
 
53
  # Download direct from S3 - requires login credentials
54
  def download_file_from_s3(bucket_name, key, local_file_path_and_name):
tools/redaction_review.py CHANGED
@@ -70,7 +70,7 @@ def update_annotator(image_annotator_object:AnnotatedImageData, page_num:int, zo
70
 
71
  number_reported = gr.Number(label = "Page (press enter to change)", value=1, precision=0)
72
 
73
- return out_image_annotator, number_reported, number_reported
74
 
75
  #print("page_num at start of update_annotator function:", page_num)
76
 
 
70
 
71
  number_reported = gr.Number(label = "Page (press enter to change)", value=1, precision=0)
72
 
73
+ return out_image_annotator, number_reported, number_reported, page_num_reported
74
 
75
  #print("page_num at start of update_annotator function:", page_num)
76