mariemerenc commited on
Commit
57053e5
·
verified ·
1 Parent(s): 87e7a8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -52
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
- # Título da aplicação
8
- st.title("Reconhecimento de LIBRAS")
9
-
10
- # Carregue o modelo treinado
11
- @st.cache_resource # Cache para carregar o modelo apenas uma vez
12
- def load_custom_model():
13
- return load_model('libras_model_v2.keras')
14
-
15
- model = load_custom_model()
16
-
17
- # Carregue as labels
18
- @st.cache_data # Cache para carregar as labels apenas uma vez
19
- def load_labels():
20
- return np.load('labels.npy', allow_pickle=True)
21
-
22
- labels = load_labels()
23
-
24
- # Função para fazer a predição em uma única imagem
25
- def predict_image(img):
26
- # Redimensione a imagem para o tamanho esperado pelo modelo (50x50)
27
- img = img.resize((50, 50))
28
- img_array = image.img_to_array(img) / 255.0
29
- img_array = np.expand_dims(img_array, axis=0)
30
-
31
- # Faça a predição
32
- preds = model.predict(img_array)
33
- pred_label = labels[np.argmax(preds)]
34
- confidence = np.max(preds) * 100 # Confiança da predição em porcentagem
35
-
36
- return pred_label, confidence
37
-
38
- # Upload da imagem
39
- uploaded_file = st.file_uploader("Escolha uma imagem...", type=["jpg", "jpeg", "png"])
40
-
41
- if uploaded_file is not None:
42
- # Carregue a imagem
43
- img = Image.open(uploaded_file)
44
-
45
- # Exiba a imagem
46
- st.image(img, caption='Imagem carregada', use_column_width=True)
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}%**")