Spaces:
Runtime error
Runtime error
Geraldine J
commited on
Commit
路
368b420
1
Parent(s):
1c4c9dd
Update dataframe and json
Browse files
app.py
CHANGED
@@ -47,6 +47,34 @@ torch.hub.download_url_to_file('https://i.pinimg.com/564x/3b/2f/d4/3b2fd4b6881b6
|
|
47 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
|
48 |
#model = torch.hub.load('path/to/yolov5', 'custom', path='/content/yolov56.pt', source='local') # local repo
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
def yolo(size, iou, conf, im):
|
52 |
try:
|
@@ -58,13 +86,14 @@ def yolo(size, iou, conf, im):
|
|
58 |
|
59 |
model.conf = conf
|
60 |
|
61 |
-
|
62 |
results2 = model(im) # inference
|
63 |
-
|
64 |
results2.render() # updates results.imgs with boxes and labels
|
65 |
-
|
|
|
|
|
|
|
66 |
except Exception as e:
|
67 |
-
|
68 |
|
69 |
#------------ Interface-------------
|
70 |
|
@@ -74,6 +103,8 @@ in3 = gr.inputs.Slider(minimum=0, maximum=1, step=0.05, default=0.50, label='Umb
|
|
74 |
in4 = gr.inputs.Image(type='pil', label="Original Image")
|
75 |
|
76 |
out2 = gr.outputs.Image(type="pil", label="Identificaci贸n con Yolov5")
|
|
|
|
|
77 |
#-------------- Text-----
|
78 |
title = 'OceanApp'
|
79 |
description = """
|
@@ -91,7 +122,7 @@ article ="<p style='text-align: center'><a href='' target='_blank'>Para mas info
|
|
91 |
|
92 |
examples = [['640',0.45, 0.75,'ejemplo1.jpg'], ['640',0.45, 0.75,'ejemplo2.jpg']]
|
93 |
|
94 |
-
iface = gr.Interface(yolo, inputs=[in1, in2, in3, in4], outputs=out2, title=title, description=description, article=article, examples=examples,theme="huggingface", analytics_enabled=False).launch(
|
95 |
debug=True)
|
96 |
|
97 |
iface.launch()
|
|
|
47 |
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt', force_reload=True, autoshape=True) # local model o google colab
|
48 |
#model = torch.hub.load('path/to/yolov5', 'custom', path='/content/yolov56.pt', source='local') # local repo
|
49 |
|
50 |
+
def listJSON(a,b,c,d):
|
51 |
+
try:
|
52 |
+
strlist =[]
|
53 |
+
strlist.append(a)
|
54 |
+
strlist.append(b)
|
55 |
+
strlist.append(c)
|
56 |
+
if d =='Pelicano\nSp':
|
57 |
+
strlist.append('Pelicano')
|
58 |
+
else:
|
59 |
+
strlist.append(d)
|
60 |
+
json_string = json.dumps(strlist)
|
61 |
+
return json_string
|
62 |
+
except Exception as e:
|
63 |
+
logging.error(e, exc_info=True)
|
64 |
+
|
65 |
+
def arrayLista(a,b):
|
66 |
+
try:
|
67 |
+
strlist =[{}]*1
|
68 |
+
strlist[0] = set()
|
69 |
+
strlist[0].add(a)
|
70 |
+
if b =='Pelicano\nSp':
|
71 |
+
strlist[0].add('Pelicano')
|
72 |
+
else:
|
73 |
+
strlist[0].add(b)
|
74 |
+
df = pd.DataFrame(strlist,columns=['Especie','Cantidad'])
|
75 |
+
return df
|
76 |
+
except Exception as e:
|
77 |
+
logging.error(e, exc_info=True)
|
78 |
|
79 |
def yolo(size, iou, conf, im):
|
80 |
try:
|
|
|
86 |
|
87 |
model.conf = conf
|
88 |
|
|
|
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:20],results3[21:32])
|
93 |
+
lista2 = arrayLista(results3[19:20],results3[21:32])
|
94 |
+
return Image.fromarray(results2.ims[0]), lista2, lista
|
95 |
except Exception as e:
|
96 |
+
logging.error(e, exc_info=True)
|
97 |
|
98 |
#------------ Interface-------------
|
99 |
|
|
|
103 |
in4 = gr.inputs.Image(type='pil', label="Original Image")
|
104 |
|
105 |
out2 = gr.outputs.Image(type="pil", label="Identificaci贸n con Yolov5")
|
106 |
+
out3 = gr.outputs.Dataframe(label="Descripci贸n")
|
107 |
+
out4 = gr.outputs.JSON(label="JSON")
|
108 |
#-------------- Text-----
|
109 |
title = 'OceanApp'
|
110 |
description = """
|
|
|
122 |
|
123 |
examples = [['640',0.45, 0.75,'ejemplo1.jpg'], ['640',0.45, 0.75,'ejemplo2.jpg']]
|
124 |
|
125 |
+
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(
|
126 |
debug=True)
|
127 |
|
128 |
iface.launch()
|