ninenox commited on
Commit
5396c98
·
verified ·
1 Parent(s): e7ea3d7

Upload folder using huggingface_hub

Browse files
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import gradio as gr
3
+ import torch
4
+ import torchvision.transforms as transforms
5
+ from PIL import Image
6
+ from torchvision import models
7
+
8
+ # ข้อความ string ค่าของ classes ที่มี
9
+ targets = ['Negative','Positive']
10
+
11
+ # เตรียม data ก่อนเข้าโมเดล
12
+ transform = transforms.Compose([
13
+ transforms.Resize(256),
14
+ transforms.CenterCrop(224),
15
+ transforms.ToTensor(),
16
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
17
+ ])
18
+
19
+ # ฟังก์ชันประมวลผลรูปภาพ
20
+ def classify_image(img):
21
+ img = Image.fromarray(img.astype('uint8'), 'RGB')
22
+ img = transform(img).unsqueeze(0)
23
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
24
+ img = img.to(device)
25
+
26
+ with torch.no_grad():
27
+ prediction = torch.nn.functional.softmax(model(img)[0], dim=0)
28
+ confidences = {targets[i]: float(prediction[i]) for i in range(2)}
29
+ return confidences
30
+
31
+ # รันโปรแกรมเว็บ gradio
32
+ demo = gr.Interface(fn=classify_image,
33
+ inputs=gr.Image(width=224, height=224),
34
+ outputs=gr.Label(num_top_classes=2),
35
+ examples=["examples/negative.jpeg", "examples/positive.jpeg"]) # ภาพตัวอย่างมาจาก folder examples
36
+
37
+ demo.launch(share=True, debug=True)
examples/.DS_Store ADDED
Binary file (6.15 kB). View file
 
examples/negative.jpeg ADDED
examples/positive.jpeg ADDED
model_blood.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:146d347cf6d13f3e7247132e72c4b1bb5690972afe129e0b5aa6d4ed7c17d824
3
+ size 94395906