shrey-14 commited on
Commit
b626a04
·
verified ·
1 Parent(s): 11c0975

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing import image
5
+ import matplotlib.pyplot as plt
6
+ import pickle
7
+
8
+ # Load the saved model
9
+ model = load_model("ASL_CNN_model.h5")
10
+
11
+ with open('label_list.pkl', 'rb') as f:
12
+ index_to_label = pickle.load(f)
13
+
14
+ IMG_HEIGHT = 128
15
+ IMG_WIDTH = 128
16
+
17
+ def predict_sign_language(img):
18
+ # Preprocess the image
19
+ img = img.resize((IMG_HEIGHT, IMG_WIDTH))
20
+ img_array = image.img_to_array(img)
21
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
22
+ img_array = img_array / 255.0 # Normalize if needed
23
+
24
+ # Make predictions
25
+ predictions = model.predict(img_array)
26
+ predicted_index = np.argmax(predictions[0]) # Get the index with the highest probability
27
+ predicted_label = index_to_label[predicted_index]
28
+
29
+ return predicted_label
30
+
31
+ # Create a Gradio interface
32
+ iface = gr.Interface(
33
+ fn=predict_sign_language,
34
+ inputs=gr.Image(type="pil", label="Input Image"), # Use 'pil' type to get a PIL image
35
+ outputs=gr.Textbox(label="Predicted Label"),
36
+ title="Sign Language Predictor",
37
+ description="<div style='text-align: center;'>Upload an image and the model will predict the sign language.</div>",
38
+ examples=[
39
+ ["L.png"],
40
+ ["lvb-cornuto5.webp"],
41
+ ["sign-language-hand-showing-c-260nw-740041291.webp"]
42
+ ]
43
+ )
44
+
45
+ # Launch the interface
46
+ if __name__ == "__main__":
47
+ iface.launch()