Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import torch
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from transformers import AutoImageProcessor, Swinv2ForImageClassification
|
| 7 |
+
|
| 8 |
+
# Page setup
|
| 9 |
+
st.set_page_config(page_title="Glaucoma Detector", layout="centered")
|
| 10 |
+
st.title("👁️ Glaucoma Detection App")
|
| 11 |
+
st.write("Upload a **fundus image** to check for signs of glaucoma using a pre-trained deep learning model.")
|
| 12 |
+
|
| 13 |
+
# File uploader
|
| 14 |
+
uploaded_file = st.file_uploader("Choose a fundus image...", type=["jpg", "jpeg", "png"])
|
| 15 |
+
|
| 16 |
+
if uploaded_file is not None:
|
| 17 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 18 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 19 |
+
|
| 20 |
+
with st.spinner("🧠 Analyzing the image..."):
|
| 21 |
+
image_np = np.array(image)
|
| 22 |
+
|
| 23 |
+
processor = AutoImageProcessor.from_pretrained("pamixsun/swinv2_tiny_for_glaucoma_classification")
|
| 24 |
+
model = Swinv2ForImageClassification.from_pretrained("pamixsun/swinv2_tiny_for_glaucoma_classification")
|
| 25 |
+
|
| 26 |
+
inputs = processor(image_np, return_tensors="pt")
|
| 27 |
+
with torch.no_grad():
|
| 28 |
+
logits = model(**inputs).logits
|
| 29 |
+
|
| 30 |
+
predicted_label = logits.argmax(-1).item()
|
| 31 |
+
label = model.config.id2label[predicted_label]
|
| 32 |
+
|
| 33 |
+
st.success(f"✅ **Prediction:** {label}")
|