images_gui / app.py
apsora's picture
Update app.py
25b1bd5 verified
raw
history blame contribute delete
904 Bytes
import torch
import timm
from PIL import Image
import torchvision.transforms as T
import gradio as gr
# load pretrained backbone and your weights if available
model = timm.create_model("efficientnet_b0", pretrained=True, num_classes=2)
model.eval()
labels = ["No Lipstick", "Lipstick"]
transform = T.Compose([
T.Resize(256),
T.CenterCrop(224),
T.ToTensor(),
T.Normalize([0.485,0.456,0.406],[0.229,0.224,0.225])
])
def predict(img):
img = transform(img).unsqueeze(0)
with torch.no_grad():
probs = torch.nn.functional.softmax(model(img), dim=1)[0]
return {labels[i]: float(probs[i]) for i in range(2)}
demo = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=2),
title="πŸ’„ Lipstick Detector",
description="Lightweight EfficientNet-B0 demo without AutoGluon"
)
if __name__ == "__main__":
demo.launch()