Spaces:
Sleeping
Sleeping
File size: 2,156 Bytes
f9dee50 bf53063 f9dee50 31c09c5 f9dee50 bf53063 f9dee50 31c09c5 bf53063 31c09c5 f9dee50 31c09c5 f9dee50 31c09c5 f9dee50 31c09c5 f9dee50 31c09c5 bf53063 f9dee50 31c09c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import gradio as gr
from fastai.vision.all import load_learner, PILImage
import os
import pathlib
if os.name == "nt": # Windows
pathlib.PosixPath = pathlib.WindowsPath
learn = load_learner("cards_classification.pkl", cpu=True)
def classify_image(image):
if image is None:
return {}
img = PILImage.create(image)
pred_class, pred_idx, probs = learn.predict(img)
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
# Create the interface
with gr.Blocks() as iface:
gr.Markdown(
"""
# π Playing Card Image Classifier
This AI model can recognize and classify images of standard playing cards using deep learning.
### How it works:
Upload an image of a playing card, and the model will predict which card it is from a full deck of cards.
### Supported Cards:
The model can identify **all standard playing cards**, including:
- Aces, numbers (2β10), Jacks, Queens, and Kings
- All four suits: Clubs, Diamonds, Hearts, and Spades
- Joker card (In total: 53 classes)
### Tips for best results:
- Make sure the card is fully visible
- Avoid heavy glare, blur, or occlusion
- One card per image works best
"""
)
with gr.Row():
with gr.Column():
input_image = gr.Image(type="pil", label="Upload Card Image")
submit_btn = gr.Button("π Identify Card", variant="primary")
with gr.Column():
output_label = gr.Label(num_top_classes=3, label="Predictions")
gr.Examples(
examples=[
["test_images/king_of_diamonds.jpg"],
["test_images/jack_of_spades.jpg"],
["test_images/ace_of_diamonds.jpg"],
["test_images/three_of_hearts.jpg"],
["test_images/ace_of_spades.jpg"]
],
inputs=input_image,
label="Try an example"
)
submit_btn.click(fn=classify_image, inputs=input_image, outputs=output_label)
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860) |