Spaces:
Sleeping

File size: 1,293 Bytes
79cbb9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
from PIL import Image
import io

st.title("Diabetic Retinopathy Classification")
st.write("Upload a retinal image to classify its DR severity.")

uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Image", use_column_width=True)
    
    if st.button("Classify Image"):
        with st.spinner("Classifying..."):
            img_bytes = io.BytesIO()
            image.save(img_bytes, format='JPEG')
            img_bytes = img_bytes.getvalue()
            
            response = requests.post("http://localhost:5000/predict", files={"file": img_bytes})
            
            if response.status_code == 200:
                result = response.json()
                st.success(f"Predicted Class: {result['class']}")
                st.write("Confidence Scores:")
                for label, prob in zip([
                    "No DR signs", "Mild (or early) NPDR", "Moderate NPDR", "Severe NPDR", "Very Severe NPDR", "PDR", "Advanced PDR"
                ], result["probabilities"]):
                    st.write(f"{label}: {prob:.4f}")
            else:
                st.error("Error: Unable to classify image")