File size: 1,393 Bytes
be92199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
40
41
42
43
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from huggingface_hub import hf_hub_download
import pickle
from PIL import Image

# Baixar os arquivos
repo_id = "davebraga/wrdbTI6"
model_path = hf_hub_download(repo_id, "trained_model.keras")
category_encoder_path = hf_hub_download(repo_id, "category_encoder.pkl")
color_encoder_path = hf_hub_download(repo_id, "color_encoder.pkl")

# Carregar modelo e encoders
model = load_model(model_path)
with open(category_encoder_path, "rb") as f:
    category_encoder = pickle.load(f)
with open(color_encoder_path, "rb") as f:
    color_encoder = pickle.load(f)

# Previsão
def predict(image):
    image = image.resize((160, 160))
    image_array = np.array(image) / 255.0
    image_array = np.expand_dims(image_array, axis=0)

    category_pred, color_pred = model.predict(image_array)
    category = category_encoder.inverse_transform([np.argmax(category_pred)])[0]
    color = color_encoder.inverse_transform([np.argmax(color_pred)])[0]

    return f"Categoria: {category}", f"Cor: {color}"

# Interface
iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil"),
    outputs=["text", "text"],
    title="Classificador de Categoria e Cor",
    description="Faça upload de uma imagem de uma peça de roupa para prever a categoria e a cor."
)

iface.launch()