Geraldine J commited on
Commit
1a545a7
·
1 Parent(s): 094aae1

Update app lists

Browse files
Files changed (1) hide show
  1. app.py +71 -71
app.py CHANGED
@@ -51,34 +51,34 @@ region = os.environ['region']
51
 
52
  # Envio de imagenes a S3
53
  def upload_file(file_name, bucket=None, object_name=None):
54
- """Upload a file to an S3 bucket
55
-
56
- :param file_name: File to upload
57
- :param bucket: Bucket to upload to
58
- :param object_name: S3 object name. If not specified then file_name is used
59
- :return: Json if file was uploaded, else False
60
- """
61
- # If S3 object_name was not specified, use file_name
62
- if object_name is None:
63
- object_name = os.path.basename(file_name+".jpg")
64
- if bucket is None:
65
- bucket = 'oceanapp'
66
- s3_client = boto3.client('s3',aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key)
67
- aws_region = boto3.session.Session().region_name
68
- # Upload the file
69
- try:
70
- with open(file_name, "rb") as f:
71
- response = s3_client.upload_fileobj(f, bucket, object_name)
72
- s3_url = f"https://{bucket}.s3.amazonaws.com/{object_name}"
73
- stado = '"url_details":[{"statusCode":200, "s3_url":"'+s3_url+'"}]'
74
- print(s3_url)
75
- except FileNotFoundError:
76
- print("The file was not found")
77
- return False
78
- except NoCredentialsError as e:
79
- logging.error(e)
80
- return False
81
- return stado
82
 
83
  #Imagen temporal guardada en upload_file
84
  def tempFileJSON(img_file):
@@ -90,53 +90,53 @@ def tempFileJSON(img_file):
90
  return uf
91
 
92
  def removeStr(string):
93
- return string.replace(" ", "")
94
-
95
- # Model
96
- model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
97
 
98
  def listJSON(a,b,c,d,e,f,resImg):
99
- x = re.findall("obo mar", d)
100
- y = re.findall("elica", d)
101
- z = re.findall("elica", f)
102
- if x:
103
- d = 'Lobo marino'
104
- if y:
105
- d = 'Pelicano'
106
- if z:
107
- f = 'Pelicano'
108
- if(d=='Lobo marino' or d=='Pelicano'):
109
- if d =='Pelicano\nSp' or d =='Pelicano\nS':
110
- d = 'Pelicano'
111
- if f!='Pelicano':
112
- strlista = '"detail":[{"quantity":"'+str(removeStr(c))+'","description":"'+str(d)+'"}]'
113
- else:
114
- strlista = '"detail":[{"quantity":"'+str(removeStr(c))+'","description":"'+str(d)+'"},{"quantity":"'+str(removeStr(e))+'","description":"'+str(f)+'"}]'
115
- strlist = '{"image":"'+str(removeStr(a))+'","size":"'+str(removeStr(b))+'",'+strlista+','+resImg+'}'
116
- json_string = json.loads(strlist)
117
- return json_string
118
 
119
  def arrayLista(a,b,c,d):
120
- x = re.findall("obo mar", b)
121
- y = re.findall("elica", b)
122
- z = re.findall("elica", d)
123
- if x:
124
- b = 'Lobo marino'
125
- if y:
126
- b = 'Pelicano'
127
- if z:
128
- d = 'Pelicano'
129
- if(b=='Lobo marino' or b=='Pelicano'):
130
- strlist =[]
131
- strlist2 =[]
132
- strlist.append(removeStr(a))
133
- strlist.append(b)
134
- if d=='Pelicano':
135
- strlist2.append(removeStr(c))
136
- strlist2.append(d)
137
- strlista = [strlist,strlist2]
138
- df = pd.DataFrame(strlista,columns=['Cantidad','Especie'])
139
- return df
 
 
 
140
 
141
  def yolo(size, iou, conf, im):
142
  try:
 
51
 
52
  # Envio de imagenes a S3
53
  def upload_file(file_name, bucket=None, object_name=None):
54
+ """Upload a file to an S3 bucket
55
+
56
+ :param file_name: File to upload
57
+ :param bucket: Bucket to upload to
58
+ :param object_name: S3 object name. If not specified then file_name is used
59
+ :return: Json if file was uploaded, else False
60
+ """
61
+ # If S3 object_name was not specified, use file_name
62
+ if object_name is None:
63
+ object_name = os.path.basename(file_name+".jpg")
64
+ if bucket is None:
65
+ bucket = 'oceanapp'
66
+ s3_client = boto3.client('s3',aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key)
67
+ aws_region = boto3.session.Session().region_name
68
+ # Upload the file
69
+ try:
70
+ with open(file_name, "rb") as f:
71
+ response = s3_client.upload_fileobj(f, bucket, object_name)
72
+ s3_url = f"https://{bucket}.s3.amazonaws.com/{object_name}"
73
+ stado = '"url_details":[{"statusCode":200, "s3_url":"'+s3_url+'"}]'
74
+ print(s3_url)
75
+ except FileNotFoundError:
76
+ print("The file was not found")
77
+ return False
78
+ except NoCredentialsError as e:
79
+ logging.error(e)
80
+ return False
81
+ return stado
82
 
83
  #Imagen temporal guardada en upload_file
84
  def tempFileJSON(img_file):
 
90
  return uf
91
 
92
  def removeStr(string):
93
+ return string.replace(" ", "")
 
 
 
94
 
95
  def listJSON(a,b,c,d,e,f,resImg):
96
+ x = re.findall("obo mar", d)
97
+ y = re.findall("elica", d)
98
+ z = re.findall("elica", f)
99
+ if x:
100
+ d = 'Lobo marino'
101
+ if y:
102
+ d = 'Pelicano'
103
+ if z:
104
+ f = 'Pelicano'
105
+ if(d=='Lobo marino' or d=='Pelicano'):
106
+ if d =='Pelicano\nSp' or d =='Pelicano\nS':
107
+ d = 'Pelicano'
108
+ if f!='Pelicano':
109
+ strlista = '"detail":[{"quantity":"'+str(removeStr(c))+'","description":"'+str(d)+'"}]'
110
+ else:
111
+ strlista = '"detail":[{"quantity":"'+str(removeStr(c))+'","description":"'+str(d)+'"},{"quantity":"'+str(removeStr(e))+'","description":"'+str(f)+'"}]'
112
+ strlist = '{"image":"'+str(removeStr(a))+'","size":"'+str(removeStr(b))+'",'+strlista+','+resImg+'}'
113
+ json_string = json.loads(strlist)
114
+ return json_string
115
 
116
  def arrayLista(a,b,c,d):
117
+ x = re.findall("obo mar", b)
118
+ y = re.findall("elica", b)
119
+ z = re.findall("elica", d)
120
+ if x:
121
+ b = 'Lobo marino'
122
+ if y:
123
+ b = 'Pelicano'
124
+ if z:
125
+ d = 'Pelicano'
126
+ if(b=='Lobo marino' or b=='Pelicano'):
127
+ strlist =[]
128
+ strlist2 =[]
129
+ strlist.append(removeStr(a))
130
+ strlist.append(b)
131
+ if d=='Pelicano':
132
+ strlist2.append(removeStr(c))
133
+ strlist2.append(d)
134
+ strlista = [strlist,strlist2]
135
+ df = pd.DataFrame(strlista,columns=['Cantidad','Especie'])
136
+ print(df)
137
+ return df
138
+ # Model
139
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
140
 
141
  def yolo(size, iou, conf, im):
142
  try: