Spaces:
Sleeping

Manj12's picture
Update app.py
8c27ffe verified
Raw History Blame Contribute Delete
1.18 kB
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
# LOAD MODEL
model = tf.keras.models.load_model("human_action_model_v3.h5")
# CLASS NAMES
class_names = [
"calling",
"clapping",
"cycling",
"dancing",
"drinking",
"eating",
"fighting",
"hugging",
"laughing",
"listening_to_music",
"running",
"sitting",
"sleeping",
"texting",
"using_laptop"
]
# PREDICTION FUNCTION
def predict_activity(image):
image = image.resize((224, 224))
image_array = np.array(image) / 255.0
image_array = np.expand_dims(image_array, axis=0)
prediction = model.predict(image_array)
predicted_class = class_names[np.argmax(prediction)]
confidence = np.max(prediction) * 100
return f"Detected Activity: {predicted_class}\nConfidence: {confidence:.2f}%"
# GRADIO INTERFACE
demo = gr.Interface(
fn=predict_activity,
inputs=gr.Image(type="pil"),
outputs="text",
title="HumanAction AI",
description="Upload an image of calling, clapping, dancing, drinking, eating, hugging, laughing, listening to music, running, sleeping, texting, using laptop."
)
demo.launch()