zarqankhn commited on
Commit
fdb33cf
·
verified ·
1 Parent(s): f6d80b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from torchvision import transforms
4
+ from model import load_model, class_names
5
+ import torch
6
+
7
+ model = load_model()
8
+
9
+ transform = transforms.Compose([
10
+ transforms.Resize((224, 224)),
11
+ transforms.ToTensor(),
12
+ transforms.Normalize([0.485, 0.456, 0.406],
13
+ [0.229, 0.224, 0.225])
14
+ ])
15
+
16
+ def predict(image):
17
+ img = image.convert("RGB")
18
+ tensor = transform(img).unsqueeze(0)
19
+ with torch.no_grad():
20
+ output = model(tensor)
21
+ probs = torch.softmax(output, dim=1).squeeze()
22
+ return {class_names[i]: float(probs[i]) for i in range(len(class_names))}
23
+
24
+ demo = gr.Interface(fn=predict,
25
+ inputs=gr.Image(type="pil"),
26
+ outputs=gr.Label(num_top_classes=2),
27
+ title="Fracture X-Ray Classifier",
28
+ description="Upload an X-ray image to detect fractures.")
29
+
30
+ demo.launch()