Spaces:
Sleeping
Sleeping
AnthonyErosion
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import os
|
2 |
-
import time
|
3 |
from bs4 import BeautifulSoup
|
4 |
from PIL import Image, ImageOps
|
5 |
import google.generativeai as genai
|
@@ -49,18 +48,17 @@ if uploaded_file is not None or photo is not None:
|
|
49 |
img = Image.open(uploaded_file).convert("RGB")
|
50 |
st.image(img, caption='Hình ảnh đã tải lên.', use_column_width=True)
|
51 |
|
52 |
-
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
with st.spinner('Đang xử lý...'):
|
62 |
prediction = model.predict(data)
|
63 |
-
time.sleep(1)
|
64 |
|
65 |
index = np.argmax(prediction)
|
66 |
class_name = class_names[index]
|
|
|
1 |
import os
|
|
|
2 |
from bs4 import BeautifulSoup
|
3 |
from PIL import Image, ImageOps
|
4 |
import google.generativeai as genai
|
|
|
48 |
img = Image.open(uploaded_file).convert("RGB")
|
49 |
st.image(img, caption='Hình ảnh đã tải lên.', use_column_width=True)
|
50 |
|
51 |
+
with st.spinner('Đang xử lý...'):
|
52 |
+
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
|
53 |
|
54 |
+
size = (224, 224)
|
55 |
+
img = ImageOps.fit(img, size, Image.Resampling.LANCZOS)
|
56 |
|
57 |
+
image_array = np.asarray(img)
|
58 |
+
normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1
|
59 |
+
data[0] = normalized_image_array
|
60 |
|
|
|
61 |
prediction = model.predict(data)
|
|
|
62 |
|
63 |
index = np.argmax(prediction)
|
64 |
class_name = class_names[index]
|