from fastai.vision.all import * from io import BytesIO import requests import streamlit as st """ # 珊瑚疾病狀態 使用卷積神經網路分類珊瑚疾病狀態以支持保護海洋生態系統目標 分類包括珊瑚白化(Coral bleaching)、珊瑚扁蟲(Coral Flatworm)、黑帶病(Black Band Disease)、蝕骨海綿(Cliona spp)、骨骼侵蝕病(Skeletal Eroding Band coral)。 #可以複製上述五種疾病的英文名稱查詢圖片,來此驗證。 """ 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 ' if pred == 'mi' else 'is not'}** an MI (heart attack). ### Rediction result: {pred} ### Probability of {pred}: {probs[key].item()*100: .2f}% """ path = "./" learn_inf = load_learner(path + "resnet34_stage-2.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)