Spaces:
Build error
Build error
Upload 2 files
Browse files- src/app.py +54 -0
- src/requirements.txt +8 -0
src/app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
import tempfile
|
| 5 |
+
import cv2
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
+
from utils.features import extract_feature_vector
|
| 8 |
+
|
| 9 |
+
st.set_page_config(page_title="ASL Alphabet Classifier", layout="centered")
|
| 10 |
+
|
| 11 |
+
# =========================
|
| 12 |
+
# LOAD MODEL FROM HF HUB
|
| 13 |
+
# =========================
|
| 14 |
+
MODEL_REPO = "bimo177x/model"
|
| 15 |
+
MODEL_FILE = "asl_random_forest_v1.joblib"
|
| 16 |
+
|
| 17 |
+
@st.cache_resource
|
| 18 |
+
def load_model():
|
| 19 |
+
model_path = hf_hub_download(
|
| 20 |
+
repo_id=MODEL_REPO,
|
| 21 |
+
filename=MODEL_FILE
|
| 22 |
+
)
|
| 23 |
+
return joblib.load(model_path)
|
| 24 |
+
|
| 25 |
+
model = load_model()
|
| 26 |
+
|
| 27 |
+
CLASS_NAMES = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
| 28 |
+
|
| 29 |
+
st.title("ASL Alphabet Image Classifier")
|
| 30 |
+
st.write("Unggah gambar tangan berpose alfabet ASL. Sistem akan memproses dan mengklasifikasinya.")
|
| 31 |
+
|
| 32 |
+
uploaded = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
|
| 33 |
+
|
| 34 |
+
if uploaded:
|
| 35 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp:
|
| 36 |
+
tmp.write(uploaded.read())
|
| 37 |
+
temp_path = tmp.name
|
| 38 |
+
|
| 39 |
+
st.image(uploaded, caption="Uploaded Image", width=300)
|
| 40 |
+
st.write("🔍 Extracting features...")
|
| 41 |
+
|
| 42 |
+
features = extract_feature_vector(temp_path)
|
| 43 |
+
|
| 44 |
+
if features is None:
|
| 45 |
+
st.error("Tidak bisa memproses gambar.")
|
| 46 |
+
else:
|
| 47 |
+
feats = features.reshape(1, -1)
|
| 48 |
+
pred = model.predict(feats)[0]
|
| 49 |
+
prob = model.predict_proba(feats)[0]
|
| 50 |
+
|
| 51 |
+
st.success(f"Prediksi: **{CLASS_NAMES[pred]}**")
|
| 52 |
+
|
| 53 |
+
st.write("Confidence:")
|
| 54 |
+
st.bar_chart(prob)
|
src/requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.37.0
|
| 2 |
+
opencv-python-headless==4.10.0.84
|
| 3 |
+
numpy==1.26.4
|
| 4 |
+
scikit-image==0.24.0
|
| 5 |
+
scikit-learn==1.4.2
|
| 6 |
+
joblib==1.4.2
|
| 7 |
+
Pillow==10.3.0
|
| 8 |
+
huggingface_hub==0.18.1
|