Spaces:
Runtime error
Runtime error
Geraldine J
commited on
Commit
•
19a62fb
1
Parent(s):
6d34899
Update json
Browse files
app.py
CHANGED
@@ -53,26 +53,20 @@ region = os.environ['region']
|
|
53 |
def removeStr(string):
|
54 |
return string.replace(" ", "")
|
55 |
|
56 |
-
def
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
strlista = '"detail":[{"quantity":"'+str(removeStr(c))+'","description":"'+str(d)+'"}]'
|
71 |
-
else:
|
72 |
-
strlista = '"detail":[{"quantity":"'+str(removeStr(c))+'","description":"'+str(d)+'"},{"quantity":"'+str(removeStr(e))+'","description":"'+str(f)+'"}]'
|
73 |
-
strlist = '{"image":"'+str(removeStr(a))+'","size":"'+str(removeStr(b))+'",'+strlista+','+resImg+'}'
|
74 |
-
json_string = json.loads(strlist)
|
75 |
-
return json_string
|
76 |
|
77 |
def arrayLista(a,b,c,d):
|
78 |
x = re.findall("obo Mar", b)
|
@@ -144,11 +138,6 @@ def yolo(size, iou, conf, im):
|
|
144 |
'''Wrapper fn for gradio'''
|
145 |
# gain
|
146 |
g = (int(size) / max(im.size))
|
147 |
-
# resize
|
148 |
-
if(max(im.size)>900 and g>0.4):
|
149 |
-
g=0.3
|
150 |
-
if(max(im.size)>2000 and g>0.4):
|
151 |
-
g=0.1
|
152 |
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS)
|
153 |
|
154 |
model.iou = iou
|
@@ -159,13 +148,15 @@ def yolo(size, iou, conf, im):
|
|
159 |
# updates results.imgs with boxes and labels
|
160 |
results2.render()
|
161 |
results3 = str(results2)
|
|
|
|
|
162 |
#Transformando la img en bytes
|
163 |
pil_im = Image.fromarray(results2.ims[0])
|
164 |
b = io.BytesIO()
|
165 |
pil_im.save(b, 'jpeg')
|
166 |
im_bytes = b.getvalue()
|
167 |
fileImg = tempFileJSON(im_bytes)
|
168 |
-
lista
|
169 |
lista2 = arrayLista(results3[19:21],results3[22:32], results3[34:36], results3[37:45])
|
170 |
return Image.fromarray(results2.ims[0]), lista2, lista
|
171 |
except Exception as e:
|
|
|
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)
|
|
|
138 |
'''Wrapper fn for gradio'''
|
139 |
# gain
|
140 |
g = (int(size) / max(im.size))
|
|
|
|
|
|
|
|
|
|
|
141 |
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS)
|
142 |
|
143 |
model.iou = iou
|
|
|
148 |
# updates results.imgs with boxes and labels
|
149 |
results2.render()
|
150 |
results3 = str(results2)
|
151 |
+
#Contador de especies
|
152 |
+
results5=results2.pandas().xyxy[0].sort_values('name')
|
153 |
#Transformando la img en bytes
|
154 |
pil_im = Image.fromarray(results2.ims[0])
|
155 |
b = io.BytesIO()
|
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:
|