Spaces:
Sleeping
Sleeping
File size: 1,449 Bytes
9fea7bd f62b6c1 e8e50ac f62b6c1 6b48a2c 9fea7bd e8e50ac 9fea7bd 6b48a2c 9fea7bd 6b48a2c 9fea7bd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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 |