mhue commited on
Commit
69c7815
·
verified ·
1 Parent(s): 5c7e9e8

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +2 -8
  2. app.py +35 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Skin Scan
3
- emoji: 🐢
4
- colorFrom: indigo
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 5.34.2
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: skin-scan
3
+ app_file: app.py
 
 
4
  sdk: gradio
5
  sdk_version: 5.34.2
 
 
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from PIL import Image
4
+ import torch
5
+ import torchvision.transforms as T
6
+ import timm
7
+
8
+ # Load model
9
+ model = timm.create_model("efficientnet_b3a", pretrained=True, num_classes=2)
10
+ model.load_state_dict(torch.load("model.pth", map_location="cpu"))
11
+ model.eval()
12
+
13
+ # Transform
14
+ transform = T.Compose([
15
+ T.Resize((224, 224)),
16
+ T.ToTensor(),
17
+ T.Normalize([0.5]*3, [0.5]*3)
18
+ ])
19
+
20
+ labels = ["Benign", "Malignant"]
21
+
22
+ def predict(img):
23
+ img = transform(img).unsqueeze(0)
24
+ with torch.no_grad():
25
+ outputs = model(img)
26
+ probs = torch.nn.functional.softmax(outputs[0], dim=0)
27
+ return {labels[i]: float(probs[i]) for i in range(2)}
28
+
29
+ demo = gr.Interface(fn=predict,
30
+ inputs=gr.Image(type="pil"),
31
+ outputs=gr.Label(num_top_classes=2),
32
+ examples=["example1.jpg", "example2.jpg"])
33
+
34
+ demo.launch()
35
+