Spaces:
Runtime error
Runtime error
Geraldine J
commited on
Commit
·
992f75b
1
Parent(s):
ffd9cf3
Modify arrayLista and JSON
Browse files
app.py
CHANGED
@@ -36,6 +36,7 @@ import pandas as pd
|
|
36 |
import torch
|
37 |
import logging
|
38 |
import json
|
|
|
39 |
from PIL import Image
|
40 |
|
41 |
# Images
|
@@ -49,32 +50,51 @@ torch.hub.download_url_to_file('https://i.pinimg.com/564x/3b/2f/d4/3b2fd4b6881b6
|
|
49 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
|
50 |
#model = torch.hub.load('path/to/yolov5', 'custom', path='/content/yolov56.pt', source='local') # local repo
|
51 |
|
|
|
|
|
|
|
52 |
def listJSON(a,b,c,d,e,f):
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
55 |
d = 'Pelicano'
|
56 |
-
if
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
def arrayLista(a,b,c,d):
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
if
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
strlist.append(b)
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
|
79 |
def yolo(size, iou, conf, im):
|
80 |
try:
|
@@ -89,8 +109,8 @@ def yolo(size, iou, conf, im):
|
|
89 |
results2 = model(im) # inference
|
90 |
results2.render() # updates results.imgs with boxes and labels
|
91 |
results3 = str(results2)
|
92 |
-
lista = listJSON(results3[0:9], results3[11:18] ,results3[19:
|
93 |
-
lista2 = arrayLista(results3[19:
|
94 |
return Image.fromarray(results2.ims[0]), lista2, lista
|
95 |
except Exception as e:
|
96 |
logging.error(e, exc_info=True)
|
|
|
36 |
import torch
|
37 |
import logging
|
38 |
import json
|
39 |
+
import re
|
40 |
from PIL import Image
|
41 |
|
42 |
# Images
|
|
|
50 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
|
51 |
#model = torch.hub.load('path/to/yolov5', 'custom', path='/content/yolov56.pt', source='local') # local repo
|
52 |
|
53 |
+
def removeStr(string):
|
54 |
+
return string.replace(" ", "")
|
55 |
+
|
56 |
def listJSON(a,b,c,d,e,f):
|
57 |
+
x = re.findall("obo mar", d)
|
58 |
+
y = re.findall("elica", d)
|
59 |
+
z = re.findall("elica", f)
|
60 |
+
if x:
|
61 |
+
d = 'Lobo marino'
|
62 |
+
if y:
|
63 |
d = 'Pelicano'
|
64 |
+
if z:
|
65 |
+
f = 'Pelicano'
|
66 |
+
if(d=='Lobo marino' or d=='Pelicano'):
|
67 |
+
if d =='Pelicano\nSp' or d =='Pelicano\nS':
|
68 |
+
d = 'Pelicano'
|
69 |
+
if f!='Pelicano':
|
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+'}'
|
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)
|
79 |
+
y = re.findall("elica", b)
|
80 |
+
z = re.findall("elica", d)
|
81 |
+
if x:
|
82 |
+
b = 'Lobo marino'
|
83 |
+
if y:
|
84 |
+
b = 'Pelicano'
|
85 |
+
if z:
|
86 |
+
d = 'Pelicano'
|
87 |
+
if(b=='Lobo marino' or b=='Pelicano'):
|
88 |
+
strlist =[]
|
89 |
+
strlist2 =[]
|
90 |
+
strlist.append(removeStr(a))
|
91 |
strlist.append(b)
|
92 |
+
if d=='Pelicano':
|
93 |
+
strlist2.append(removeStr(c))
|
94 |
+
strlist2.append(d)
|
95 |
+
strlista = [strlist,strlist2]
|
96 |
+
df = pd.DataFrame(strlista,columns=['Cantidad','Especie'])
|
97 |
+
return df
|
98 |
|
99 |
def yolo(size, iou, conf, im):
|
100 |
try:
|
|
|
109 |
results2 = model(im) # inference
|
110 |
results2.render() # updates results.imgs with boxes and labels
|
111 |
results3 = str(results2)
|
112 |
+
lista = listJSON(results3[0:9], results3[11:18] ,results3[19:21],results3[22:32], results3[35:37], results3[37:45])
|
113 |
+
lista2 = arrayLista(results3[19:21],results3[22:32], results3[35:37], results3[37:45])
|
114 |
return Image.fromarray(results2.ims[0]), lista2, lista
|
115 |
except Exception as e:
|
116 |
logging.error(e, exc_info=True)
|