Asseh commited on
Commit
6d138f7
·
verified ·
1 Parent(s): 543967c

Update App.py

Browse files
Files changed (1) hide show
  1. App.py +13 -15
App.py CHANGED
@@ -3,20 +3,18 @@ from transformers import pipeline
3
 
4
  classifier = pipeline("image-classification", model="Asseh/Ball_Classification")
5
 
6
- # Function to classify images into 7 classes
7
- def image_classifier(inp):
8
- # Dummy classification logic
9
- # Generating random confidence scores for each class
10
- confidence_scores = np.random.rand(7)
11
- # Normalizing confidence scores to sum up to 1
12
- confidence_scores /= np.sum(confidence_scores)
13
- # Creating a dictionary with class labels and corresponding confidence scores
14
- classes = ['american_football', 'baseball', 'basketball', 'billiard_ball', 'bowling_ball','cricket_ball', 'football', 'golf_ball', 'hockey_ball', 'hockey_puck', 'rugby_ball', 'shuttlecock', 'table_tennis_ball', 'tennis_ball', 'volleyball']
15
- result = {classes[i]: confidence_scores[i] for i in range(15)}
16
- return result
17
 
18
- # Creating Gradio interface
19
- demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
20
 
21
- if name == "main":
22
- demo.launch()
 
 
 
 
 
 
 
 
 
3
 
4
  classifier = pipeline("image-classification", model="Asseh/Ball_Classification")
5
 
6
+ def predict(input_img):
7
+ predictions = classifier(input_img)
8
+ return input_img, {p["label"]: p["score"] for p in predictions}
 
 
 
 
 
 
 
 
9
 
 
 
10
 
11
+ gradio_app = gr.Interface(
12
+ predict,
13
+ inputs = gr.Image(label = "Select Image", sources=['upload', 'webcam'], type="pil"),
14
+ outputs = [gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=15)],
15
+
16
+ title="Which type of ball"
17
+ )
18
+
19
+ if __name__ == "__main__":
20
+ gradio_app.launch()