classification / app.py
srinuksv's picture
Update app.py
1be4a62 verified
raw
history blame
1.86 kB
from gradio import Interface, Image, Label
import tensorflow as tf
# Load your TensorFlow model
model = tf.keras.models.load_model("traffic.h5")
# Define your class names if needed
class_names = ['Asian-Green-Bee-Eater', 'Brown-Headed-Barbet', 'Cattle-Egret', 'Common-Kingfisher', 'Common-Myna', 'House-Crow', 'Indian-Grey-Hornbill', 'Indian-Peacock', 'Indian-Roller', 'White-Breasted-Kingfisher']
Class_names=['15 kmph', '18', '19', '30 kmph', '4 weehler', '40 kmph', '5 kmp only', '50 kmph', '51', '52', '53', '56', '57', '60 kmph', '70 kmph', '8', '80 kmph', '9', 'bicycle', 'chemical caution', 'cycle lane', 'dead end', 'go a ahead', 'home zone', 'horn', 'left dent curve', 'left service road', 'no 4-wheeler', 'no entry', 'no horn', 'no left turn', 'no over cross', 'no right and left turn', 'no right turn', 'no stopping and standing', 'no u-turn', 'proceed straight or turn right', 'railway gate', 'railway station', 'right service road', 'right v-dent curve', 'ring road', 'school zone', 'series of bends', 'side road left', 'side road right', 'sidewalk intersection', 'sland', 'traffic lights', 'turn left', 'turn right', 'turn right or left', 'u-turn', 'uphill', 'v-cuts', 'working area', 'zebra-crossing']
# Function to make predictions
def classify_image(image):
# Preprocess the image
img = tf.image.resize(image, (224, 224))
img = tf.expand_dims(img, 0) # Add batch dimension
# Make prediction
prediction = model.predict(img)
predicted_class = Class_names[prediction.argmax()]
return predicted_class
# Gradio interface
image = Image() # Remove the `shape` argument
label = Label()
# Create interface
interface = Interface(classify_image, image, label,
title="traffic sign detection ",
description="Upload an image of a traffic sign to classify its sign. ").launch()