Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load your model
|
| 7 |
+
model = tf.keras.models.load_model("vgg17.keras")
|
| 8 |
+
|
| 9 |
+
# Your class labels (replace with yours)
|
| 10 |
+
labels = {
|
| 11 |
+
0: 'A',
|
| 12 |
+
1: 'B',
|
| 13 |
+
2: 'C',
|
| 14 |
+
3: 'D',
|
| 15 |
+
4: 'E',
|
| 16 |
+
5: 'F',
|
| 17 |
+
6: 'G',
|
| 18 |
+
7: 'H',
|
| 19 |
+
8: 'I',
|
| 20 |
+
9: 'J',
|
| 21 |
+
10: 'K',
|
| 22 |
+
11: 'L',
|
| 23 |
+
12: 'M',
|
| 24 |
+
13: 'N',
|
| 25 |
+
14: 'O',
|
| 26 |
+
15: 'P',
|
| 27 |
+
16: 'Q',
|
| 28 |
+
17: 'R',
|
| 29 |
+
18: 'S',
|
| 30 |
+
19: 'T',
|
| 31 |
+
20: 'U',
|
| 32 |
+
21: 'V',
|
| 33 |
+
22: 'W',
|
| 34 |
+
23: 'X',
|
| 35 |
+
24: 'Y',
|
| 36 |
+
25: 'Z',
|
| 37 |
+
26: 'del',
|
| 38 |
+
27: 'nothing',
|
| 39 |
+
28: 'space'
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
def predict(img):
|
| 43 |
+
img = img.resize((200, 200))
|
| 44 |
+
img = np.array(img) / 255.0
|
| 45 |
+
img = np.expand_dims(img, axis=0)
|
| 46 |
+
prediction = model.predict(img)[0]
|
| 47 |
+
class_id = np.argmax(prediction)
|
| 48 |
+
confidence = prediction[class_id]
|
| 49 |
+
|
| 50 |
+
return {
|
| 51 |
+
labels[class_id]: float(confidence)
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
# Interface
|
| 55 |
+
demo = gr.Interface(
|
| 56 |
+
fn=predict,
|
| 57 |
+
inputs=gr.Image(type="pil"),
|
| 58 |
+
outputs=gr.Label(num_top_classes=5),
|
| 59 |
+
title="ASL Sign Language Recognition"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
demo.launch()
|