Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -46,6 +46,18 @@ model = models[model_name]
|
|
46 |
file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
47 |
# file ='hmnist_28_28_RGB.csv'
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
classes = {4: ('nv', ' melanocytic nevi'), 6: ('mel', 'melanoma'),
|
50 |
2 :('bkl', 'benign keratosis-like lesions'), 1:('bcc' , ' basal cell carcinoma'),
|
51 |
5: ('vasc', ' pyogenic granulomas and hemorrhage'),
|
@@ -53,17 +65,22 @@ classes = {4: ('nv', ' melanocytic nevi'), 6: ('mel', 'melanoma'),
|
|
53 |
3: ('df', 'dermatofibroma')}
|
54 |
|
55 |
|
56 |
-
if file is not None:
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
# Save the uploaded file to the temporary directory
|
61 |
-
with open(temp_file_path, "wb") as f:
|
62 |
-
|
63 |
|
64 |
-
img = cv2.imread(file)
|
65 |
# cv2_imshow(img)
|
66 |
-
img1 = cv2.resize(
|
67 |
result = model.predict(img1.reshape(1, 28, 28, 3))
|
68 |
max_prob = max(result[0])
|
69 |
class_ind = list(result[0]).index(max_prob)
|
@@ -87,7 +104,7 @@ if file is not None:
|
|
87 |
col1, col2 = st.columns(2)
|
88 |
with col1:
|
89 |
st.header("Input Image")
|
90 |
-
st.image(
|
91 |
with col2:
|
92 |
st.header("Prediction")
|
93 |
st.write(class_name)
|
|
|
46 |
file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
47 |
# file ='hmnist_28_28_RGB.csv'
|
48 |
|
49 |
+
|
50 |
+
|
51 |
+
# uploaded_file = st.file_uploader("Choose a image file", type="jpg")
|
52 |
+
|
53 |
+
if uploaded_file is not None:
|
54 |
+
# Convert the file to an opencv image.
|
55 |
+
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
56 |
+
opencv_image = cv2.imdecode(file_bytes, 1)
|
57 |
+
|
58 |
+
st.image(opencv_image, channels="BGR")
|
59 |
+
|
60 |
+
|
61 |
classes = {4: ('nv', ' melanocytic nevi'), 6: ('mel', 'melanoma'),
|
62 |
2 :('bkl', 'benign keratosis-like lesions'), 1:('bcc' , ' basal cell carcinoma'),
|
63 |
5: ('vasc', ' pyogenic granulomas and hemorrhage'),
|
|
|
65 |
3: ('df', 'dermatofibroma')}
|
66 |
|
67 |
|
68 |
+
if file is not None:
|
69 |
+
|
70 |
+
file_bytes = np.asarray(bytearray(file.read()), dtype=np.uint8)
|
71 |
+
opencv_image = cv2.imdecode(file_bytes, 1)
|
72 |
+
|
73 |
+
|
74 |
+
# temp_dir = tempfile.TemporaryDirectory()
|
75 |
+
# temp_file_path = temp_dir.name + "/" + file.name
|
76 |
|
77 |
+
# # Save the uploaded file to the temporary directory
|
78 |
+
# with open(temp_file_path, "wb") as f:
|
79 |
+
# f.write(file.read())
|
80 |
|
81 |
+
# img = cv2.imread(file)
|
82 |
# cv2_imshow(img)
|
83 |
+
img1 = cv2.resize(opencv_image, (28, 28))
|
84 |
result = model.predict(img1.reshape(1, 28, 28, 3))
|
85 |
max_prob = max(result[0])
|
86 |
class_ind = list(result[0]).index(max_prob)
|
|
|
104 |
col1, col2 = st.columns(2)
|
105 |
with col1:
|
106 |
st.header("Input Image")
|
107 |
+
st.image(opencv_image, channels="BGR")
|
108 |
with col2:
|
109 |
st.header("Prediction")
|
110 |
st.write(class_name)
|