Jainam117 commited on
Commit
1e44634
·
verified ·
1 Parent(s): dce82ea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from huggingface_hub import from_pretrained_keras
3
+ from PIL import Image
4
+ import numpy as np
5
+ import tensorflow as tf
6
+
7
+ @st.cache_resource
8
+ def load_model():
9
+ model = from_pretrained_keras("Jainam117/Sign_Langauge_digit_classification")
10
+ return model
11
+
12
+
13
+ def preprocess_image(image):
14
+
15
+ image = image.convert("L")
16
+ image = image.resize((224, 224)) # Resize to 224x224, which the model expects
17
+ image_array = np.array(image)
18
+ image_array = image_array / 255.0
19
+ image_array = np.expand_dims(image_array, axis=-1)
20
+ image_array = np.expand_dims(image_array, axis=0)
21
+ return image_array
22
+
23
+
24
+ def classify_image(model, image_array):
25
+ predictions = model.predict(image_array)
26
+ predicted_label = np.argmax(predictions, axis=1)[0]
27
+ return predicted_label
28
+
29
+ st.title("Sign Language Digit Classification")
30
+ st.write("Upload an image of a hand showing a digit, and the model will classify the digit.")
31
+
32
+
33
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
34
+
35
+ if uploaded_file is not None:
36
+
37
+ image = Image.open(uploaded_file)
38
+ st.image(image, caption="Uploaded Image", use_column_width=True)
39
+
40
+ model = load_model()
41
+
42
+ preprocessed_image = preprocess_image(image)
43
+
44
+ predicted_digit = classify_image(model, preprocessed_image)
45
+
46
+ st.write(f"Predicted Digit: {predicted_digit}")