Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- src/app.py +34 -0
- src/classes.txt +3 -0
- src/mobilenetv2.pth +3 -0
- src/requirement.txt +5 -0
src/app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import torch
|
| 3 |
+
import torchvision.transforms as transforms
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# โหลดโมเดล
|
| 7 |
+
model = torch.load('mobilenetv2.pth', map_location=torch.device('cpu'))
|
| 8 |
+
model.eval()
|
| 9 |
+
|
| 10 |
+
# โหลด label
|
| 11 |
+
with open('classes.txt', 'r') as f:
|
| 12 |
+
class_names = [line.strip() for line in f]
|
| 13 |
+
|
| 14 |
+
# UI
|
| 15 |
+
st.title("🔥 MobileNetV2 Classifier")
|
| 16 |
+
uploaded_file = st.file_uploader("อัปโหลดภาพ", type=["jpg", "png", "jpeg"])
|
| 17 |
+
|
| 18 |
+
if uploaded_file:
|
| 19 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 20 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 21 |
+
|
| 22 |
+
transform = transforms.Compose([
|
| 23 |
+
transforms.Resize((224, 224)),
|
| 24 |
+
transforms.ToTensor(),
|
| 25 |
+
])
|
| 26 |
+
img_tensor = transform(image).unsqueeze(0)
|
| 27 |
+
|
| 28 |
+
with torch.no_grad():
|
| 29 |
+
outputs = model(img_tensor)
|
| 30 |
+
probs = torch.softmax(outputs, dim=1)
|
| 31 |
+
pred_class = class_names[probs.argmax().item()]
|
| 32 |
+
confidence = probs.max().item() * 100
|
| 33 |
+
|
| 34 |
+
st.markdown(f"### 🔍 คำทำนาย: `{pred_class}` ({confidence:.2f}%)")
|
src/classes.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
undercooked
|
| 2 |
+
raw
|
| 3 |
+
cooked
|
src/mobilenetv2.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a0492bc75adb877de8e722cbdfad8cf1ef319457984d273595a05b11275407d5
|
| 3 |
+
size 9156406
|
src/requirement.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
torchvision
|
| 3 |
+
Pillow
|
| 4 |
+
streamlit
|
| 5 |
+
pandas
|