Geraldine J commited on
Commit
ffd9cf3
1 Parent(s): 135b6f6

Modify arrayLista and JSON

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -49,26 +49,30 @@ 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):
53
- strlist =[]
54
- strlist.append(a)
55
- strlist.append(b)
56
- strlist.append(c)
57
  if d =='Pelicano\nSp':
58
- strlist.append('Pelicano')
 
 
59
  else:
60
- strlist.append(d)
61
- json_string = json.dumps(strlist)
 
62
  return json_string
63
 
64
- def arrayLista(a,b):
65
  strlist =[]
 
66
  strlist.append(a)
67
  if b =='Pelicano\nSp':
68
  strlist.append('Pelicano')
69
  else:
70
  strlist.append(b)
71
- strlista = [strlist]
 
 
 
72
  df = pd.DataFrame(strlista,columns=['Cantidad','Especie'])
73
  return df
74
 
@@ -85,8 +89,8 @@ def yolo(size, iou, conf, im):
85
  results2 = model(im) # inference
86
  results2.render() # updates results.imgs with boxes and labels
87
  results3 = str(results2)
88
- lista = listJSON(results3[0:9], results3[11:18] ,results3[19:20],results3[21:32])
89
- lista2 = arrayLista(results3[19:20],results3[21:32])
90
  return Image.fromarray(results2.ims[0]), lista2, lista
91
  except Exception as e:
92
  logging.error(e, exc_info=True)
 
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
+ #for n in
 
 
 
54
  if d =='Pelicano\nSp':
55
+ d = 'Pelicano'
56
+ if f!='Pelicano':
57
+ strlista = '"detail":[{"quantity":"'+str(c)+'","description":"'+str(d)+'"}]'
58
  else:
59
+ strlista = '"detail":[{"quantity":"'+str(c)+'","description":"'+str(d)+'"},{"quantity":"'+str(e)+'","description":"'+str(f)+'"}]'
60
+ strlist = '{"image":"'+str(a)+'","size":"'+str(b)+'",'+strlista+'}'
61
+ json_string = json.loads(strlist)
62
  return json_string
63
 
64
+ def arrayLista(a,b,c,d):
65
  strlist =[]
66
+ strlist2 =[]
67
  strlist.append(a)
68
  if b =='Pelicano\nSp':
69
  strlist.append('Pelicano')
70
  else:
71
  strlist.append(b)
72
+ if d=='Pelicano':
73
+ strlist2.append(c)
74
+ strlist2.append(d)
75
+ strlista = [strlist,strlist2]
76
  df = pd.DataFrame(strlista,columns=['Cantidad','Especie'])
77
  return df
78
 
 
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], results3[35:36], results3[37:45])
93
+ lista2 = arrayLista(results3[19:20],results3[21:32], results3[35:36], results3[37:45])
94
  return Image.fromarray(results2.ims[0]), lista2, lista
95
  except Exception as e:
96
  logging.error(e, exc_info=True)