Spaces:
Sleeping
Sleeping
Update App.py
Browse files
App.py
CHANGED
|
@@ -3,20 +3,18 @@ from transformers import pipeline
|
|
| 3 |
|
| 4 |
classifier = pipeline("image-classification", model="Asseh/Ball_Classification")
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 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 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|