Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -483,7 +483,6 @@
|
|
483 |
# )
|
484 |
# iface.launch()
|
485 |
|
486 |
-
|
487 |
import gradio as gr
|
488 |
import numpy as np
|
489 |
import cv2 as cv
|
@@ -516,6 +515,7 @@ messages = [{"role": "system", "content": system}]
|
|
516 |
def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
517 |
if Textbox3 == code:
|
518 |
imageData = None
|
|
|
519 |
if Images is not None:
|
520 |
output = []
|
521 |
headers = {
|
@@ -524,13 +524,12 @@ 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 |
image_base64 = base64.b64encode(get_image.content).decode("utf-8")
|
529 |
image_data_url = f"data:image/png;base64,{image_base64}"
|
530 |
|
531 |
random_id = random.randint(1000, 9999)
|
532 |
-
|
533 |
-
filename = f"image_{random_id}{file_extension}"
|
534 |
with open(filename, "wb") as file:
|
535 |
file.write(get_image.content)
|
536 |
print(f"Saved image as: {filename}")
|
@@ -544,11 +543,11 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
544 |
else:
|
545 |
pass
|
546 |
|
547 |
-
if
|
548 |
-
image
|
|
|
549 |
image = cv.resize(image, (224, 224))
|
550 |
image_array = np.asarray(image)
|
551 |
-
image_data = cv.resize(imageData, (224, 224))
|
552 |
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
|
553 |
data[0] = normalized_image_array
|
554 |
|
@@ -620,7 +619,7 @@ def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
|
620 |
messages.append({"role": "user", "content": UserInput})
|
621 |
|
622 |
headers = {
|
623 |
-
"Content-Type": "application
|
624 |
"Authorization": f"Bearer {auth}"
|
625 |
}
|
626 |
|
|
|
483 |
# )
|
484 |
# iface.launch()
|
485 |
|
|
|
486 |
import gradio as gr
|
487 |
import numpy as np
|
488 |
import cv2 as cv
|
|
|
515 |
def classify(platform, UserInput, Images, Textbox2, Textbox3):
|
516 |
if Textbox3 == code:
|
517 |
imageData = None
|
518 |
+
image_data_url = None # Initialize image_data_url
|
519 |
if Images is not None:
|
520 |
output = []
|
521 |
headers = {
|
|
|
524 |
if platform == "wh":
|
525 |
get_image = requests.get(Images, headers=headers)
|
526 |
if get_image.status_code == 200:
|
527 |
+
# Correct base64 encoding and URL creation
|
528 |
image_base64 = base64.b64encode(get_image.content).decode("utf-8")
|
529 |
image_data_url = f"data:image/png;base64,{image_base64}"
|
530 |
|
531 |
random_id = random.randint(1000, 9999)
|
532 |
+
filename = f"image_{random_id}"
|
|
|
533 |
with open(filename, "wb") as file:
|
534 |
file.write(get_image.content)
|
535 |
print(f"Saved image as: {filename}")
|
|
|
543 |
else:
|
544 |
pass
|
545 |
|
546 |
+
if image_data_url is not None:
|
547 |
+
# Load the image from image_data_url
|
548 |
+
image = cv.imread(image_data_url)
|
549 |
image = cv.resize(image, (224, 224))
|
550 |
image_array = np.asarray(image)
|
|
|
551 |
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
|
552 |
data[0] = normalized_image_array
|
553 |
|
|
|
619 |
messages.append({"role": "user", "content": UserInput})
|
620 |
|
621 |
headers = {
|
622 |
+
"Content-Type": "application/json",
|
623 |
"Authorization": f"Bearer {auth}"
|
624 |
}
|
625 |
|