Spaces:
Runtime error
Runtime error
Geraldine J
commited on
Commit
•
9d3f2c3
1
Parent(s):
c15464d
Update json and size
Browse files
app.py
CHANGED
@@ -53,6 +53,20 @@ region = os.environ['region']
|
|
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,21 +129,6 @@ def upload_file(file_name, bucket=None, object_name=None):
|
|
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,7 +155,8 @@ def yolo(size, iou, conf, im):
|
|
156 |
pil_im.save(b, 'jpeg')
|
157 |
im_bytes = b.getvalue()
|
158 |
fileImg = tempFileJSON(im_bytes)
|
159 |
-
|
|
|
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:
|
@@ -190,7 +190,7 @@ article ="<p style='text-align: center'><a href='' target='_blank'>Para mas info
|
|
190 |
examples = [['640',0.45, 0.75,'ejemplo1.jpg'], ['640',0.45, 0.75,'ejemplo2.jpg']]
|
191 |
|
192 |
iface = gr.Interface(yolo, inputs=[in1, in2, in3, in4], outputs=[out2,out3,out4], title=title, description=description, article=article, examples=examples,theme="huggingface", analytics_enabled=False).launch(
|
193 |
-
debug=True)
|
194 |
|
195 |
iface.launch()
|
196 |
|
|
|
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 |
+
for i in range(0, dfEspecies['name'].size):
|
61 |
+
if(dfEspecies['name'][i] == 'Lobo marino'):
|
62 |
+
numLobos= numLobos + 1
|
63 |
+
if(dfEspecies['name'][i] == 'Pelicano'):
|
64 |
+
numPelicanos= numPelicanos + 1
|
65 |
+
strlista = '"detail":[{"quantity":"'+str(numLobos)+'","description":"Lobo marino"},{"quantity":"'+str(numPelicanos)+'","description":"Pelicano"}]'
|
66 |
+
data = '{"image":"'+str(removeStr(datay[0:9]))+'","size":"'+str(removeStr(datay[11:18]))+'",'+strlista+','+resImg+'}'
|
67 |
+
json_data = json.loads(data)
|
68 |
+
return json_data
|
69 |
+
|
70 |
def arrayLista(a,b,c,d):
|
71 |
x = re.findall("obo Mar", b)
|
72 |
y = re.findall("elica", b)
|
|
|
129 |
return False
|
130 |
return stado
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
# Model
|
133 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
|
134 |
|
|
|
155 |
pil_im.save(b, 'jpeg')
|
156 |
im_bytes = b.getvalue()
|
157 |
fileImg = tempFileJSON(im_bytes)
|
158 |
+
#Enviando la informacion al contador de especies
|
159 |
+
results6 = qtyEspecies(results5,results3,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:
|
|
|
190 |
examples = [['640',0.45, 0.75,'ejemplo1.jpg'], ['640',0.45, 0.75,'ejemplo2.jpg']]
|
191 |
|
192 |
iface = gr.Interface(yolo, inputs=[in1, in2, in3, in4], outputs=[out2,out3,out4], title=title, description=description, article=article, examples=examples,theme="huggingface", analytics_enabled=False).launch(
|
193 |
+
debug=True, share=True)
|
194 |
|
195 |
iface.launch()
|
196 |
|