Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,47 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import numpy as np
|
| 3 |
-
from keras.models import load_model
|
| 4 |
-
from keras.preprocessing import image
|
| 5 |
-
from PIL import Image
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
uploaded_file
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
st.
|
| 47 |
-
|
| 48 |
-
# Faça a predição
|
| 49 |
-
pred_label, confidence = predict_image(img)
|
| 50 |
-
|
| 51 |
-
# Exiba o resultado
|
| 52 |
-
st.success(f"Predição: **{pred_label}**")
|
| 53 |
st.info(f"Confiança: **{confidence:.2f}%**")
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
from keras.models import load_model
|
| 4 |
+
from keras.preprocessing import image
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
st.title("Reconhecimento de LIBRAS")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@st.cache_resource
|
| 11 |
+
def load_custom_model():
|
| 12 |
+
return load_model('libras_model_v2.keras')
|
| 13 |
+
|
| 14 |
+
model = load_custom_model()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@st.cache_data
|
| 18 |
+
def load_labels():
|
| 19 |
+
return np.load('labels.npy', allow_pickle=True)
|
| 20 |
+
|
| 21 |
+
labels = load_labels()
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def predict_image(img):
|
| 25 |
+
img = img.resize((50, 50))
|
| 26 |
+
img_array = image.img_to_array(img) / 255.0
|
| 27 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
preds = model.predict(img_array)
|
| 31 |
+
pred_label = labels[np.argmax(preds)]
|
| 32 |
+
confidence = np.max(preds) * 100
|
| 33 |
+
|
| 34 |
+
return pred_label, confidence
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
uploaded_file = st.file_uploader("Escolha uma imagem...", type=["jpg", "jpeg", "png"])
|
| 38 |
+
|
| 39 |
+
if uploaded_file is not None:
|
| 40 |
+
img = Image.open(uploaded_file)
|
| 41 |
+
|
| 42 |
+
st.image(img, caption='Imagem carregada', use_column_width=True)
|
| 43 |
+
|
| 44 |
+
pred_label, confidence = predict_image(img)
|
| 45 |
+
|
| 46 |
+
st.success(f"Predição: **{pred_label}**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
st.info(f"Confiança: **{confidence:.2f}%**")
|