prithivMLmods commited on
Commit
810c199
·
verified ·
1 Parent(s): 01187b9

Delete alphabet_sign_language_detection.py

Browse files
Files changed (1) hide show
  1. alphabet_sign_language_detection.py +0 -45
alphabet_sign_language_detection.py DELETED
@@ -1,45 +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/Alphabet-Sign-Language-Detection"
11
- model = SiglipForImageClassification.from_pretrained(model_name)
12
- processor = AutoImageProcessor.from_pretrained(model_name)
13
-
14
- @spaces.GPU
15
- def sign_language_classification(image):
16
- """Predicts sign language alphabet category 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": "A", "1": "B", "2": "C", "3": "D", "4": "E", "5": "F", "6": "G", "7": "H", "8": "I", "9": "J",
27
- "10": "K", "11": "L", "12": "M", "13": "N", "14": "O", "15": "P", "16": "Q", "17": "R", "18": "S", "19": "T",
28
- "20": "U", "21": "V", "22": "W", "23": "X", "24": "Y", "25": "Z"
29
- }
30
- predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
31
-
32
- return predictions
33
-
34
- # Create Gradio interface
35
- iface = gr.Interface(
36
- fn=sign_language_classification,
37
- inputs=gr.Image(type="numpy"),
38
- outputs=gr.Label(label="Prediction Scores"),
39
- title="Alphabet Sign Language Detection",
40
- description="Upload an image to classify it into one of the 26 sign language alphabet categories."
41
- )
42
-
43
- # Launch the app
44
- if __name__ == "__main__":
45
- iface.launch()