Spaces:
Sleeping
Sleeping
Adding bar chart for predicted probabilites
Browse files123440 unmodified lines45464748495051525354555657583 unmodified lines62636465666768import gradio as grimport numpy as npimport cv2import tensorflow as tf40 unmodified linesdef predict_asl(frame):"""Predict the ASL sign from the webcam frame."""# Preprocess the frameprocessed_frame = preprocess_frame(frame)# Make a predictionpredictions = model.predict(processed_frame)# Get the class with the highest probabilitypredicted_label = labels[np.argmax(predictions)]return predicted_labelcss = """.my-group {max-width: 500px !important; max-height: 500px !important;}.my-column {display: flex !important; justify-content: center !important; align-items: center !important};"""3 unmodified lineswith gr.Group(elem_classes=["my-group"]):input_img = gr.Image(sources=["webcam"], type="numpy", streaming=True, label="Webcam Input")output_label = gr.Label(label="Predicted ASL Sign")input_img.stream(predict_asl, [input_img], [output_label], time_limit=300, stream_every=0.1)demo.launch()1234540 unmodified lines464748495051525354555657585960616263646566673 unmodified lines7172737475767778import gradio as grimport matplotlib.pyplot as pltimport numpy as npimport cv2import tensorflow as tf40 unmodified linesdef predict_asl(frame):"""Predict the ASL sign and return the label and probabilities."""processed_frame = preprocess_frame(frame)predictions = model.predict(processed_frame) # Predict probabilitiespredicted_label = labels[np.argmax(predictions)] # Get the class with the highest probability# Generate a bar chart for probabilitiesfig, ax = plt.subplots(figsize=(6, 4))ax.bar(labels, predictions[0])ax.set_title("Class Probabilities")ax.set_ylabel("Probability")ax.set_xlabel("ASL Classes")ax.set_xticks(range(len(labels)))ax.set_xticklabels(labels, rotation=45)plt.tight_layout()return predicted_label, figcss = """.my-group {max-width: 500px !important; max-height: 500px !important;}.my-column {display: flex !important; justify-content: center !important; align-items: center !important};"""3 unmodified lineswith gr.Group(elem_classes=["my-group"]):input_img = gr.Image(sources=["webcam"], type="numpy", streaming=True, label="Webcam Input")output_label = gr.Label(label="Predicted ASL Sign")output_plot = gr.Plot(label="Class Probabilities")input_img.stream(predict_asl, [input_img], [output_label], time_limit=300, stream_every=0.5)demo.launch()
app.py+18-8