Download streamlit_app.py from helviz/deploy_ml: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/helviz/deploy_ml/resolve/main/streamlit_app.py
- Command line
-
hf download hf://spaces/helviz/deploy_ml/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/helviz/deploy_ml/resolve/main/streamlit_app.py
1.29 kB
| 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") | |