prithivMLmods commited on
Commit
8f83a2b
·
verified ·
1 Parent(s): aca06e7

Delete gym_workout_classification.py

Browse files
Files changed (1) hide show
  1. gym_workout_classification.py +0 -48
gym_workout_classification.py DELETED
@@ -1,48 +0,0 @@
1
- import gradio as gr
2
- import spaces
3
- from transformers import AutoImageProcessor
4
- from transformers import SiglipForImageClassification
5
- from transformers.image_utils import load_image
6
- from PIL import Image
7
- import torch
8
-
9
- # Load model and processor
10
- model_name = "prithivMLmods/Gym-Workout-Classifier-SigLIP2"
11
- model = SiglipForImageClassification.from_pretrained(model_name)
12
- processor = AutoImageProcessor.from_pretrained(model_name)
13
-
14
- @spaces.GPU
15
- def workout_classification(image):
16
- """Predicts workout exercise classification for an image."""
17
- image = Image.fromarray(image).convert("RGB")
18
- inputs = processor(images=image, return_tensors="pt")
19
-
20
- with torch.no_grad():
21
- outputs = model(**inputs)
22
- logits = outputs.logits
23
- probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
24
-
25
- labels = {
26
- "0": "barbell biceps curl", "1": "bench press", "2": "chest fly machine", "3": "deadlift",
27
- "4": "decline bench press", "5": "hammer curl", "6": "hip thrust", "7": "incline bench press",
28
- "8": "lat pulldown", "9": "lateral raises", "10": "leg extension", "11": "leg raises",
29
- "12": "plank", "13": "pull up", "14": "push up", "15": "romanian deadlift",
30
- "16": "russian twist", "17": "shoulder press", "18": "squat", "19": "t bar row",
31
- "20": "tricep dips", "21": "tricep pushdown"
32
- }
33
- predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
34
-
35
- return predictions
36
-
37
- # Create Gradio interface
38
- iface = gr.Interface(
39
- fn=workout_classification,
40
- inputs=gr.Image(type="numpy"),
41
- outputs=gr.Label(label="Prediction Scores"),
42
- title="Gym Workout Classification",
43
- description="Upload an image to classify the workout exercise."
44
- )
45
-
46
- # Launch the app
47
- if __name__ == "__main__":
48
- iface.launch()