Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,34 @@
|
|
1 |
-
# Human
|
2 |
|
3 |
-
## LOADING MODULES
|
4 |
|
|
|
5 |
|
|
|
6 |
from transformers import pipeline
|
7 |
-
# from PIL import Image
|
8 |
-
# import requests
|
9 |
-
import gradio as gr
|
10 |
-
|
11 |
pipe = pipeline("image-classification", "rvv-karma/Human-Action-Recognition-VIT-Base-patch16-224")
|
12 |
|
13 |
def classify_image(input):
|
|
|
14 |
predictions = pipe(image)
|
15 |
return {prediction["label"]: prediction["score"] for prediction in predictions}
|
16 |
|
17 |
-
|
18 |
-
# Output:
|
19 |
-
# [{'score': 0.9918079972267151, 'label': 'dancing'},
|
20 |
-
# {'score': 0.00207977625541389, 'label': 'clapping'},
|
21 |
-
# {'score': 0.0015223610680550337, 'label': 'running'},
|
22 |
-
# {'score': 0.0009153694845736027, 'label': 'fighting'},
|
23 |
-
# {'score': 0.0006987180095165968, 'label': 'sitting'}]
|
24 |
|
|
|
25 |
|
26 |
ex=[['cat2.jpg'],
|
27 |
['dog2.jpeg'],
|
28 |
['cat3.jpg'],
|
29 |
['dog.jpeg']]
|
30 |
|
|
|
|
|
31 |
"""
|
32 |
## RUNNING WEB UI"""
|
33 |
|
34 |
-
image = gr.
|
35 |
-
label = gr.
|
36 |
|
37 |
-
|
38 |
-
height=600, width=1200, examples=ex, theme='peach').launch(debug=True)
|
39 |
|
|
|
|
|
|
1 |
+
# rvv-karma/Human-Action-Recognition
|
2 |
|
|
|
3 |
|
4 |
+
## Creating prediction pipeline
|
5 |
|
6 |
+
from PIL import Image
|
7 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
8 |
pipe = pipeline("image-classification", "rvv-karma/Human-Action-Recognition-VIT-Base-patch16-224")
|
9 |
|
10 |
def classify_image(input):
|
11 |
+
image = Image.fromarray(input.astype('uint8'), 'RGB')
|
12 |
predictions = pipe(image)
|
13 |
return {prediction["label"]: prediction["score"] for prediction in predictions}
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
import gradio as gr
|
17 |
|
18 |
ex=[['cat2.jpg'],
|
19 |
['dog2.jpeg'],
|
20 |
['cat3.jpg'],
|
21 |
['dog.jpeg']]
|
22 |
|
23 |
+
ex = []
|
24 |
+
|
25 |
"""
|
26 |
## RUNNING WEB UI"""
|
27 |
|
28 |
+
image = gr.Image()
|
29 |
+
label = gr.Label(num_top_classes=5)
|
30 |
|
31 |
+
description = "Categories: " + "'" + "', '".join(pipe.model.config.label2id.keys()) + "'"
|
|
|
32 |
|
33 |
+
gr.Interface(fn=classify_image, inputs=image, outputs=label, title='Human Action Recognition',
|
34 |
+
description=description, examples=ex, theme='peach').launch(height=1000, width=1600, debug=True)
|