Spaces:
Sleeping
Sleeping
dealing with png
Browse files- app.py +15 -9
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -30,6 +30,9 @@ def load_cnn():
|
|
| 30 |
|
| 31 |
# Função para pré-processar a imagem e extrair características
|
| 32 |
def extract_features(image, cnn_model):
|
|
|
|
|
|
|
|
|
|
| 33 |
transform = transforms.Compose([
|
| 34 |
transforms.Resize((256, 256)),
|
| 35 |
transforms.ToTensor(),
|
|
@@ -51,15 +54,18 @@ cnn_model = load_cnn()
|
|
| 51 |
# Upload da imagem
|
| 52 |
uploaded_file = st.file_uploader("Escolha uma imagem...", type=["jpg", "jpeg", "png"])
|
| 53 |
if uploaded_file is not None:
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Função para pré-processar a imagem e extrair características
|
| 32 |
def extract_features(image, cnn_model):
|
| 33 |
+
# Converter a imagem para RGB (remover canal alfa se existir)
|
| 34 |
+
image = image.convert("RGB")
|
| 35 |
+
|
| 36 |
transform = transforms.Compose([
|
| 37 |
transforms.Resize((256, 256)),
|
| 38 |
transforms.ToTensor(),
|
|
|
|
| 54 |
# Upload da imagem
|
| 55 |
uploaded_file = st.file_uploader("Escolha uma imagem...", type=["jpg", "jpeg", "png"])
|
| 56 |
if uploaded_file is not None:
|
| 57 |
+
try:
|
| 58 |
+
image = Image.open(uploaded_file)
|
| 59 |
+
st.image(image, caption="Imagem enviada", use_column_width=True)
|
| 60 |
|
| 61 |
+
# Extrair características da imagem usando a CNN
|
| 62 |
+
image_features = extract_features(image, cnn_model)
|
| 63 |
|
| 64 |
+
# Fazer a previsão
|
| 65 |
+
prediction = model.predict(image_features)
|
| 66 |
+
predicted_class = label_encoder.inverse_transform(prediction)[0]
|
| 67 |
|
| 68 |
+
# Exibir o resultado
|
| 69 |
+
st.write(f"Classificação: **{predicted_class}**")
|
| 70 |
+
except Exception as e:
|
| 71 |
+
st.error(f"Erro ao processar a imagem: {e}")
|
requirements.txt
CHANGED
|
@@ -9,4 +9,4 @@ matplotlib==3.7.2
|
|
| 9 |
streamlit==1.27.0
|
| 10 |
joblib==1.3.2
|
| 11 |
huggingface_hub==0.19.4
|
| 12 |
-
Pillow
|
|
|
|
| 9 |
streamlit==1.27.0
|
| 10 |
joblib==1.3.2
|
| 11 |
huggingface_hub==0.19.4
|
| 12 |
+
Pillow==10.0.0
|