Geraldine J commited on
Commit
c15464d
1 Parent(s): 8be3011

Update json and size

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -53,21 +53,6 @@ region = os.environ['region']
53
  def removeStr(string):
54
  return string.replace(" ", "")
55
 
56
- def qtyEspecies(datax, datay, resImg):
57
- numLobos = 0
58
- numPelicanos = 0
59
- dfEspecies = pd.DataFrame(datax)
60
- datay = str(datay)
61
- for i in range(0, dfEspecies['name'].size):
62
- if(dfEspecies['name'][i] == 'Lobo marino'):
63
- numLobos= numLobos + 1
64
- if(dfEspecies['name'][i] == 'Pelicano'):
65
- numPelicanos= numPelicanos + 1
66
- strlista = '"detail":[{"quantity":"'+str(numLobos)+'","description":"Lobo marino"},{"quantity":"'+str(numPelicanos)+'","description":"Pelicano"}]'
67
- data = '{"image":"'+str(removeStr(datay[0:9]))+'","size":"'+str(removeStr(datay[11:18]))+'",'+strlista+','+resImg+'}'
68
- json_data = json.loads(data)
69
- return json_data
70
-
71
  def arrayLista(a,b,c,d):
72
  x = re.findall("obo Mar", b)
73
  y = re.findall("elica", b)
@@ -130,6 +115,21 @@ def upload_file(file_name, bucket=None, object_name=None):
130
  return False
131
  return stado
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  # Model
134
  model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
135
 
@@ -156,9 +156,9 @@ def yolo(size, iou, conf, im):
156
  pil_im.save(b, 'jpeg')
157
  im_bytes = b.getvalue()
158
  fileImg = tempFileJSON(im_bytes)
159
- lista=qtyEspecies(results5,results2,fileImg)
160
  lista2 = arrayLista(results3[19:21],results3[22:32], results3[34:36], results3[37:45])
161
- return Image.fromarray(results2.ims[0]), lista2, lista
162
  except Exception as e:
163
  logging.error(e, exc_info=True)
164
 
 
53
  def removeStr(string):
54
  return string.replace(" ", "")
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  def arrayLista(a,b,c,d):
57
  x = re.findall("obo Mar", b)
58
  y = re.findall("elica", b)
 
115
  return False
116
  return stado
117
 
118
+ def qtyEspecies(datax, datay, resImg):
119
+ numLobos = 0
120
+ numPelicanos = 0
121
+ dfEspecies = pd.DataFrame(datax)
122
+ datay = str(datay)
123
+ for i in range(0, dfEspecies['name'].size):
124
+ if(dfEspecies['name'][i] == 'Lobo marino'):
125
+ numLobos= numLobos + 1
126
+ if(dfEspecies['name'][i] == 'Pelicano'):
127
+ numPelicanos= numPelicanos + 1
128
+ strlista = '"detail":[{"quantity":"'+str(numLobos)+'","description":"Lobo marino"},{"quantity":"'+str(numPelicanos)+'","description":"Pelicano"}]'
129
+ data = '{"image":"'+str(removeStr(datay[0:9]))+'","size":"'+str(removeStr(datay[11:18]))+'",'+strlista+','+resImg+'}'
130
+ json_data = json.loads(data)
131
+ return json_data
132
+
133
  # Model
134
  model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
135
 
 
156
  pil_im.save(b, 'jpeg')
157
  im_bytes = b.getvalue()
158
  fileImg = tempFileJSON(im_bytes)
159
+ results6 = qtyEspecies(results5,results2,fileImg)
160
  lista2 = arrayLista(results3[19:21],results3[22:32], results3[34:36], results3[37:45])
161
+ return Image.fromarray(results2.ims[0]), lista2, results6
162
  except Exception as e:
163
  logging.error(e, exc_info=True)
164