tommy24 commited on
Commit
c38acde
·
1 Parent(s): 43f241c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -319,6 +319,7 @@ import gradio as gr
319
  import numpy as np
320
  import cv2 as cv
321
  import requests
 
322
  import os
323
  import tensorflow as tf
324
 
@@ -356,19 +357,27 @@ def classify(platform, UserInput, Image, Textbox2, Textbox3):
356
  if platform == "wh":
357
  get_image = requests.get(Image, headers=headers)
358
  if get_image.status_code == 200:
359
- print(get_image.content)
360
- imageData = cv.imdecode(np.asarray(bytearray(get_image.content), dtype="uint8"), cv.IMREAD_COLOR)
 
 
 
361
  elif platform == "web":
362
  print("WEB")
363
  # Handle web case if needed
364
  else:
365
  pass
366
 
367
- image_data = cv.resize(imageData, (224, 224))
368
  normalized_image_array = (image_data.astype(np.float32) / 127.0) - 1
 
369
  data[0] = normalized_image_array
370
-
371
  prediction = model.predict(data)
 
 
 
 
 
372
 
373
  max_label_index = None
374
  max_prediction_value = -1
 
319
  import numpy as np
320
  import cv2 as cv
321
  import requests
322
+ from PIL import Image
323
  import os
324
  import tensorflow as tf
325
 
 
357
  if platform == "wh":
358
  get_image = requests.get(Image, headers=headers)
359
  if get_image.status_code == 200:
360
+ # print(get_image.content)
361
+ # imageData = cv.imdecode(np.asarray(bytearray(get_image.content), dtype="uint8"), cv.IMREAD_COLOR)
362
+ image_bytes = get_image.content
363
+ image = Image.open(io.BytesIO(image_bytes))
364
+ image_data = cv.cvtColor(np.array(image), cv.COLOR_RGB2BGR)
365
  elif platform == "web":
366
  print("WEB")
367
  # Handle web case if needed
368
  else:
369
  pass
370
 
371
+ image_data = cv.resize(image_data, (224, 224))
372
  normalized_image_array = (image_data.astype(np.float32) / 127.0) - 1
373
+ data = np.zeros((1, 224, 224, 3))
374
  data[0] = normalized_image_array
 
375
  prediction = model.predict(data)
376
+ # image_data = cv.resize(imageData, (224, 224))
377
+ # normalized_image_array = (image_data.astype(np.float32) / 127.0) - 1
378
+ # data[0] = normalized_image_array
379
+
380
+ # prediction = model.predict(data)
381
 
382
  max_label_index = None
383
  max_prediction_value = -1