tommy24 commited on
Commit
8cfd2ad
·
1 Parent(s): e67965c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -359,10 +359,17 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
359
  get_image = requests.get(Images, headers=headers)
360
  if get_image.status_code == 200:
361
  # print(get_image.content)
362
- # imageData = cv.imdecode(np.asarray(bytearray(get_image.content), dtype="uint8"), cv.IMREAD_COLOR)
363
- image_bytes = get_image.content
364
- image = Image.open(io.BytesIO(image_bytes))
365
- imageData = cv.cvtColor(np.array(image), cv.COLOR_RGB2BGR)
 
 
 
 
 
 
 
366
  elif platform == "web":
367
  print("WEB")
368
  # Handle web case if needed
@@ -370,15 +377,10 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
370
  pass
371
 
372
  image_data = cv.resize(imageData, (224, 224))
373
- normalized_image_array = (imageData.astype(np.float32) / 127.0) - 1
374
- data = np.zeros((1, 224, 224, 3))
375
  data[0] = normalized_image_array
376
- prediction = model.predict(data)
377
- # image_data = cv.resize(imageData, (224, 224))
378
- # normalized_image_array = (image_data.astype(np.float32) / 127.0) - 1
379
- # data[0] = normalized_image_array
380
 
381
- # prediction = model.predict(data)
382
 
383
  max_label_index = None
384
  max_prediction_value = -1
 
359
  get_image = requests.get(Images, headers=headers)
360
  if get_image.status_code == 200:
361
  # print(get_image.content)
362
+ random_id = random.randint(1000, 9999)
363
+
364
+ file_extension = ".png"
365
+ filename = f"image_{random_id}{file_extension}"
366
+ with open(filename, "wb") as file:
367
+ file.write(get_image.content)
368
+
369
+ print(f"Saved image as: {filename}")
370
+
371
+ full_path = os.path.join(os.getcwd(), filename)
372
+ print(f"Saved image as: {full_path}")
373
  elif platform == "web":
374
  print("WEB")
375
  # Handle web case if needed
 
377
  pass
378
 
379
  image_data = cv.resize(imageData, (224, 224))
380
+ normalized_image_array = (image_data.astype(np.float32) / 127.0) - 1
 
381
  data[0] = normalized_image_array
 
 
 
 
382
 
383
+ prediction = model.predict(data)
384
 
385
  max_label_index = None
386
  max_prediction_value = -1