Spaces:
Sleeping
Sleeping
Create app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637import gradio as grimport numpy as npfrom pathlib import Pathfrom PIL import Imagefrom tensorflow.keras.models import load_model
CLASS_NAMES = [ "calling", "clapping", "cycling", "dancing", "drinking", "eating", "fighting", "hugging", "laughing", "listening_to_music", "running", "sitting", "sleeping", "texting", "using_laptop",]
IMAGE_SIZE = (224, 224)MODEL_PATH = Path("model/human_action_model_v2.h5")
model = load_model(MODEL_PATH)
def predict_activity(image): image = image.convert("RGB").resize(IMAGE_SIZE) image_array = np.asarray(image, dtype=np.float32) / 255.0 image_batch = np.expand_dims(image_array, axis=0)
predictions = model.predict(image_batch, verbose=0) scores = np.asarray(predictions).reshape(-1)
predicted_index = int(np.argmax(scores)) return CLASS_NAMES[predicted_index]
demo = gr.Interface( fn=predict_activity, inputs=gr.Image(type="pil", label="Upload image"), outputs=gr.Textbox(label="Detected Activity"), title="HumanAction AI", description="Upload a JPG or PNG image to predict the human action.")
demo.launch()app.pyAdded+37