from fastai.vision.all import * from io import BytesIO import requests import streamlit as st """ # HeartNet This is a classifier for images of 12-lead EKGs. It will attempt to detect whether the EKG indicates an acute MI. It was trained on simulated images. """ def predict(img): st.image(img, caption="Your image", use_column_width=True) pred, key, probs = learn_inf.predict(img) # st.write(learn_inf.predict(img)) f""" ## This **{'is cordana' if pred == 'cordana' else 'is pestalotiopsis' if pred == 'pestalotiopsis' else 'is sigatoka' if pred == 'sigatoka' else 'is healthy'}**. ### Prediction result: {pred} ### Probability of {pred}: {probs[key].item()*100: .2f}% """ img1 = Image.open('/home/user/app/img1.jpg') img2 = Image.open('/home/user/app/img2.jpg') img3 = Image.open('/home/user/app/img3.jpg') col1, col2, col3 = st.columns(3) with col1: st.image(img1, caption="Image 1", use_column_width=True) with col2: st.image(img2, caption="Image 2", use_column_width=True) with col3: st.image(img3, caption="Image 3", use_column_width=True) path = "./" learn_inf = load_learner(path + "demo_model.pkl") option = st.radio("", ["Upload Image", "Image URL"]) if option == "Upload Image": uploaded_file = st.file_uploader("Please upload an image.") if uploaded_file is not None: img = PILImage.create(uploaded_file) predict(img) else: url = st.text_input("Please input a url.") if url != "": try: response = requests.get(url) pil_img = PILImage.create(BytesIO(response.content)) predict(pil_img) except: st.text("Problem reading image from", url)