Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -350,7 +350,7 @@ messages = [
|
|
350 |
def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
351 |
if Textbox3 == code:
|
352 |
imageData = None
|
353 |
-
if
|
354 |
output = []
|
355 |
headers = {
|
356 |
"Authorization": f"Bearer {auth2}"
|
@@ -358,14 +358,11 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
358 |
if platform == "wh":
|
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)
|
@@ -376,8 +373,11 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
376 |
else:
|
377 |
pass
|
378 |
|
|
|
|
|
|
|
379 |
image_data = cv.resize(imageData, (224, 224))
|
380 |
-
normalized_image_array = (
|
381 |
data[0] = normalized_image_array
|
382 |
|
383 |
prediction = model.predict(data)
|
|
|
350 |
def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
351 |
if Textbox3 == code:
|
352 |
imageData = None
|
353 |
+
if Images is not None:
|
354 |
output = []
|
355 |
headers = {
|
356 |
"Authorization": f"Bearer {auth2}"
|
|
|
358 |
if platform == "wh":
|
359 |
get_image = requests.get(Images, headers=headers)
|
360 |
if get_image.status_code == 200:
|
|
|
361 |
random_id = random.randint(1000, 9999)
|
|
|
362 |
file_extension = ".png"
|
363 |
filename = f"image_{random_id}{file_extension}"
|
364 |
with open(filename, "wb") as file:
|
365 |
file.write(get_image.content)
|
|
|
366 |
print(f"Saved image as: {filename}")
|
367 |
|
368 |
full_path = os.path.join(os.getcwd(), filename)
|
|
|
373 |
else:
|
374 |
pass
|
375 |
|
376 |
+
image = cv.imread(full_path)
|
377 |
+
image = cv.resize(image, (224, 224))
|
378 |
+
image_array = np.asarray(image)
|
379 |
image_data = cv.resize(imageData, (224, 224))
|
380 |
+
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
|
381 |
data[0] = normalized_image_array
|
382 |
|
383 |
prediction = model.predict(data)
|