Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536import gradio as grimport tensorflow as tfimport numpy as npfrom PIL import Imageimport cv2
# Load modelmodel = tf.keras.models.load_model("keras_model.h5")
# Replace this with your actual label list if you have itlabels = ["Good Posture", "Bad Posture"]
def predict_from_webcam(frame): # Resize frame to match model input size (usually 224x224 for Teachable Machine) img = cv2.resize(frame, (224, 224)) img = img / 255.0 # normalize img = np.expand_dims(img, axis=0) # batch dimension
# Predict prediction = model.predict(img)[0] top_label = labels[np.argmax(prediction)] confidence = np.max(prediction)
return f"{top_label} ({confidence*100:.2f}%)"
# Gradio interfacedemo = gr.Interface( fn=predict_from_webcam, inputs=gr.Image(source="webcam", streaming=True), outputs=gr.Text(), live=True, title="Posture Detector", description="Detects if your posture is good or bad using a webcam model trained with Teachable Machine.")
demo.launch()app.pyAdded+36