Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -482,7 +482,6 @@
|
|
482 |
# title="Classifier",
|
483 |
# )
|
484 |
# iface.launch()
|
485 |
-
|
486 |
import gradio as gr
|
487 |
import numpy as np
|
488 |
import cv2 as cv
|
@@ -524,19 +523,11 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
524 |
if platform == "wh":
|
525 |
get_image = requests.get(Images, headers=headers)
|
526 |
if get_image.status_code == 200:
|
527 |
-
|
528 |
-
# Correct base64 encoding and URL creation
|
529 |
image_base64 = base64.b64encode(get_image.content).decode("utf-8")
|
530 |
-
image_data_url = f"data:image/png;base64,{image_base64}"
|
531 |
-
|
532 |
-
# random_id = random.randint(1000, 9999)
|
533 |
-
# filename = f"image_{random_id}"
|
534 |
-
# with open(filename, "wb") as file:
|
535 |
-
# file.write(get_image.content)
|
536 |
-
# print(f"Saved image as: {filename}")
|
537 |
|
538 |
-
#
|
539 |
-
|
540 |
|
541 |
elif platform == "web":
|
542 |
print("WEB")
|
@@ -546,7 +537,10 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
546 |
|
547 |
if image_data_url is not None:
|
548 |
# Load the image from image_data_url
|
549 |
-
|
|
|
|
|
|
|
550 |
image = cv.resize(image, (224, 224))
|
551 |
image_array = np.asarray(image)
|
552 |
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
|
|
|
482 |
# title="Classifier",
|
483 |
# )
|
484 |
# iface.launch()
|
|
|
485 |
import gradio as gr
|
486 |
import numpy as np
|
487 |
import cv2 as cv
|
|
|
523 |
if platform == "wh":
|
524 |
get_image = requests.get(Images, headers=headers)
|
525 |
if get_image.status_code == 200:
|
526 |
+
# Convert the image data to base64
|
|
|
527 |
image_base64 = base64.b64encode(get_image.content).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
528 |
|
529 |
+
# Create a data URL
|
530 |
+
image_data_url = f"data:image/png;base64,{image_base64}"
|
531 |
|
532 |
elif platform == "web":
|
533 |
print("WEB")
|
|
|
537 |
|
538 |
if image_data_url is not None:
|
539 |
# Load the image from image_data_url
|
540 |
+
image_data = base64.b64decode(image_base64)
|
541 |
+
nparr = np.frombuffer(image_data, np.uint8)
|
542 |
+
image = cv.imdecode(nparr, cv.IMREAD_COLOR)
|
543 |
+
|
544 |
image = cv.resize(image, (224, 224))
|
545 |
image_array = np.asarray(image)
|
546 |
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
|