Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +52 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,54 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
""
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|