| import streamlit as st | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.preprocessing import image | |
| import numpy as np | |
| from PIL import Image | |
| model = load_model("src/card_model_1.h5") | |
| class_labels = [ | |
| 'ace of clubs', 'ace of diamonds', 'ace of hearts', 'ace of spades', | |
| 'eight of clubs', 'eight of diamonds', 'eight of hearts', 'eight of spades', | |
| 'five of clubs', 'five of diamonds', 'five of hearts', 'five of spades', | |
| 'four of clubs', 'four of diamonds', 'four of hearts', 'four of spades', | |
| 'jack of clubs', 'jack of diamonds', 'jack of hearts', 'jack of spades', | |
| 'joker', | |
| 'king of clubs', 'king of diamonds', 'king of hearts', 'king of spades', | |
| 'nine of clubs', 'nine of diamonds', 'nine of hearts', 'nine of spades', | |
| 'queen of clubs', 'queen of diamonds', 'queen of hearts', 'queen of spades', | |
| 'seven of clubs', 'seven of diamonds', 'seven of hearts', 'seven of spades', | |
| 'six of clubs', 'six of diamonds', 'six of hearts', 'six of spades', | |
| 'ten of clubs', 'ten of diamonds', 'ten of hearts', 'ten of spades', | |
| 'three of clubs', 'three of diamonds', 'three of hearts', 'three of spades', | |
| 'two of clubs', 'two of diamonds', 'two of hearts', 'two of spades' | |
| ] | |
| st.set_page_config(page_title="Card Classifier", layout="centered") | |
| st.title("π :red[Playing] Card Classifier") | |
| st.markdown("Upload an image of a card and the model will predict its name.") | |
| uploaded_file = st.file_uploader("π€ Upload a card image...", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file: | |
| img = Image.open(uploaded_file).convert("RGB") | |
| st.image(img, caption="Uploaded Image") | |
| img = img.resize((224,224)) | |
| img_array = image.img_to_array(img) / 255.0 | |
| img_array = np.expand_dims(img_array, axis=0) | |
| prediction = model.predict(img_array) | |
| predicted_class = class_labels[np.argmax(prediction)] | |
| confidence = float(np.max(prediction)) | |
| st.success(f"Predicted Card: **{predicted_class}**") | |
| st.info(f"Confidence: {confidence:.2%}") | |