Spaces:
Sleeping

File size: 1,183 Bytes
2fd0824
a1e30a5
2fd0824
 
 
a1e30a5
6ed1b2b
a1e30a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2fd0824
 
a1e30a5
 
2fd0824
a1e30a5
2fd0824
a1e30a5
 
 
 
 
 
 
2fd0824
a1e30a5
2fd0824
a1e30a5
2fd0824
a1e30a5
2fd0824
 
a1e30a5
 
2fd0824
8c27ffe
2fd0824
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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()