American Young Coder (AYC)

AYC logo
Loading Events

« All Events

  • This event has passed.

7 PM – AI / ML – Shawn

October 24, 2023 @ 7:00 pm - 8:00 pm

Today We Did
  1. Continued streamlit app
  1. Try writing the rest of the as shown:
    import streamlit as stimport urllib.request
    from import *

    def label_func(f): return f[0].isupper()
    # Load the pre-trained model
    model = load_learner(‘my_model.pkl’)

    # Define a function to make predictions
    def predict(image):
    img = PILImage.create(image) # Use PILImage.create to open the image
    pred_class, pred_idx, outputs = model.predict(img)
    likelihood_is_cat = outputs[1].item()
    if likelihood_is_cat > 0.9:
    return “Cat”
    elif likelihood_is_cat < 0.1:
    return “Dog”
    return “Not sure… try another picture!”

    # Streamlit app title and description
    st.title(“Cat vs. Dog Classifier”)
    st.write(“Upload an image, and I’ll tell you whether it’s a cat or a dog!”)

    # File uploader widget
    uploaded_file = st.file_uploader(“Choose an image…”, type=[“jpg”, “png”, “jpeg”])

    if uploaded_file is not None:
    # Display the uploaded image
    st.image(uploaded_file, caption=”Uploaded Image”, use_column_width=True)

    # Make predictions on the uploaded image
    if st.button(“Predict”):
    prediction = predict(uploaded_file)

    # Add a footer
    st.text(“Built with Streamlit and Fastai”)

  2. Run streamlit run in the terminal to see the website in action! For windows users, it should be py -m streamlit run

Email me at if you have any questions.


October 24, 2023
7:00 pm - 8:00 pm
Verified by MonsterInsights