Spaces:
Sleeping
Sleeping
Download app.py from adarsh-007/Cards_Classification: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/spaces/adarsh-007/Cards_Classification/resolve/main/app.py
- Command line
-
hf download hf://spaces/adarsh-007/Cards_Classification/app.py
-
curl -L -o app.py https://huggingface.co/spaces/adarsh-007/Cards_Classification/resolve/main/app.py
2.16 kB
| 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) |