Rifky commited on
Commit
9ce0ab5
·
1 Parent(s): eee7004

Deploy ViT classifier to Hugging Face

Browse files
Files changed (2) hide show
  1. app.py +26 -0
  2. requirements.txt +13 -3
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.makedirs(os.path.expanduser("~/.streamlit"), exist_ok=True)
3
+
4
+ import streamlit as st
5
+ from transformers import ViTFeatureExtractor, ViTForImageClassification
6
+ from PIL import Image
7
+ import torch
8
+
9
+ st.set_page_config(page_title="Cataract Detection with ViT", layout="wide")
10
+ st.title("👁️ Cataract Detection using Vision Transformer (ViT)")
11
+
12
+ uploaded_file = st.file_uploader("Upload an eye image (JPG/PNG)", type=["jpg", "jpeg", "png"])
13
+ if uploaded_file:
14
+ image = Image.open(uploaded_file).convert("RGB")
15
+ st.image(image, caption="Uploaded Image", use_column_width=True)
16
+
17
+ model_name = "Decoder24/Cataract-ViT"
18
+ model = ViTForImageClassification.from_pretrained(model_name)
19
+ extractor = ViTFeatureExtractor.from_pretrained(model_name)
20
+
21
+ inputs = extractor(images=image, return_tensors="pt")
22
+ outputs = model(**inputs)
23
+ preds = outputs.logits.softmax(dim=-1)
24
+ label = preds.argmax(dim=-1).item()
25
+
26
+ st.success(f"Predicted class: {model.config.id2label[label]}")
requirements.txt CHANGED
@@ -1,3 +1,13 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ torchaudio
4
+ timm
5
+ scikit-learn
6
+ opencv-python
7
+ matplotlib
8
+ seaborn
9
+ albumentations
10
+ wandb
11
+ streamlit
12
+ transformers
13
+ pillow