arpy8's picture
update app
6b48a2c
import requests
import streamlit as st
from config import API_URL, CLASS_LABELS
def model_page():
st.write("#### Please upload MRI scan here...")
uploaded_file = st.file_uploader("Upload MRI scan here...", type=["jpg", "png", "jpeg"], label_visibility="hidden")
predict_button = st.button("ㅤㅤPredictㅤㅤ")
if predict_button and uploaded_file:
result_ele = st.empty()
result_ele.write("Processing...")
st.image(uploaded_file, use_column_width=True)
result = predict_image(uploaded_file)
label = CLASS_LABELS[int(result['label'])]
prob = round(result['probability'], 4)*100
# According to our model, there is a 99.97% chance that this scan is from a non demented person.
result_ele.info(f"""According to our model, there is a **{prob}%** chance that this scan is from a **{label}** person.""")
st.toast("Prediction completed!", icon="🎉")
elif predict_button and not uploaded_file:
st.toast("Please upload an MRI scan first!", icon="⚠️")
def predict_image(image):
files = {'file': image}
headers = {'accept': 'application/json'}
try:
response = requests.post(API_URL, headers=headers, files=files)
response.raise_for_status()
result = response.json()
return result
except Exception as e:
st.error(f"An error occurred: {e}")
return None