Spaces:
Sleeping
Sleeping
Download app.py from Manj12/Humanrecognation01: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/Manj12/Humanrecognation01/resolve/main/app.py
- Command line
-
hf download hf://spaces/Manj12/Humanrecognation01/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Manj12/Humanrecognation01/resolve/main/app.py
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() |