fernandobarranco commited on
Commit
292a08b
1 Parent(s): 19d2c80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -9,17 +9,22 @@ from io import BytesIO
9
 
10
 
11
  def image_classifier(image, api_key):
 
12
  buffered = io.BytesIO()
13
  image = Image.fromarray(np.uint8(image))
14
  image = image.convert("RGB")
15
  image.save(buffered, quality=90, format="JPEG")
16
  img_str = base64.b64encode(buffered.getvalue())
17
  img_str = img_str.decode("ascii")
 
 
18
  headers = {'Content-Type': 'application/json', 'accept': 'application/json'}
19
  r = requests.post(f'https://classify.roboflow.com/clasificacion-sin-regularizacion/1?api_key={api_key}',
20
  data=img_str,
21
  headers=headers)
22
  preds = r.json()
 
 
23
  output = {x:round(float(y['confidence']), 3) for x,y in preds['predictions'].items()}
24
  return output
25
 
 
9
 
10
 
11
  def image_classifier(image, api_key):
12
+ # Lectura de imagen a ser predicha
13
  buffered = io.BytesIO()
14
  image = Image.fromarray(np.uint8(image))
15
  image = image.convert("RGB")
16
  image.save(buffered, quality=90, format="JPEG")
17
  img_str = base64.b64encode(buffered.getvalue())
18
  img_str = img_str.decode("ascii")
19
+
20
+ # Llamada a la API del modelo entrenado sin el uso de imágenes generadas artificialmente
21
  headers = {'Content-Type': 'application/json', 'accept': 'application/json'}
22
  r = requests.post(f'https://classify.roboflow.com/clasificacion-sin-regularizacion/1?api_key={api_key}',
23
  data=img_str,
24
  headers=headers)
25
  preds = r.json()
26
+
27
+ # Formato de predicciones para ser visualizadas con la interfaz de gradio
28
  output = {x:round(float(y['confidence']), 3) for x,y in preds['predictions'].items()}
29
  return output
30