ddnb338 commited on
Commit
79283dd
·
verified ·
1 Parent(s): 7bd73b0

Update app/app.py

Browse files
Files changed (1) hide show
  1. app/app.py +5 -27
app/app.py CHANGED
@@ -3,9 +3,7 @@ import base64
3
  from flask import Flask, render_template,request
4
  import config
5
  #newly added
6
- import json
7
- from google.cloud import storage
8
- from google.oauth2 import service_account
9
  #local imports
10
  from detection_model_run import run_detection
11
  from helper import preprocess_keypoints
@@ -15,17 +13,9 @@ from show_points import display_keypoints
15
 
16
 
17
  app = Flask(__name__)
 
18
  app.config.from_object(config)
19
 
20
- credentials_raw = os.getenv('gcp_credentials')
21
- if credentials_raw:
22
- credentials_dict = json.loads(credentials_raw)
23
- credentials = service_account.Credentials.from_service_account_info(credentials_dict)
24
- client = storage.Client(credentials=credentials)
25
- bucket = client.get_bucket('dl-individual-project')
26
- print("helloooo")
27
- else:
28
- raise EnvironmentError("Failed to get 'GCP_CREDENTIALS' from environment.")
29
 
30
  UPLOAD_FOLDER = 'captures' # Define the directory to save uploaded images
31
 
@@ -77,22 +67,10 @@ def upload():
77
  # Remove header from base64 encoded image
78
  img_data = data_url.split(',')[1]
79
 
80
- # Decode the base64 string
81
- image_data = base64.b64decode(img_data)
82
-
83
- # Create a secure filename
84
- filename = f'image_{imageID}.png'
85
-
86
- # Upload the file to GCS
87
- blob = bucket.blob(filename)
88
- blob.upload_from_string(image_data, content_type='image/png')
89
- blob.make_public()
90
-
91
  # Save the image to a file
92
- #image_path = os.path.join(app.config['UPLOAD_FOLDER'], f'image_{imageID}.png')
93
- #with open( image_path,'wb') as f:
94
- #f.write(base64.b64decode(img_data))
95
- image_path = blob.public_url
96
  print("hello",image_path)
97
 
98
 
 
3
  from flask import Flask, render_template,request
4
  import config
5
  #newly added
6
+ from flask_cors import CORS
 
 
7
  #local imports
8
  from detection_model_run import run_detection
9
  from helper import preprocess_keypoints
 
13
 
14
 
15
  app = Flask(__name__)
16
+ CORS(app)
17
  app.config.from_object(config)
18
 
 
 
 
 
 
 
 
 
 
19
 
20
  UPLOAD_FOLDER = 'captures' # Define the directory to save uploaded images
21
 
 
67
  # Remove header from base64 encoded image
68
  img_data = data_url.split(',')[1]
69
 
 
 
 
 
 
 
 
 
 
 
 
70
  # Save the image to a file
71
+ image_path = os.path.join(app.config['UPLOAD_FOLDER'], f'image_{imageID}.png')
72
+ with open( image_path,'wb') as f:
73
+ f.write(base64.b64decode(img_data))
 
74
  print("hello",image_path)
75
 
76