Spaces:
Runtime error

File size: 2,017 Bytes
8db07f9
 
 
 
 
 
 
d078dc8
 
8db07f9
 
 
 
 
 
 
 
 
 
 
 
 
 
d078dc8
8db07f9
 
 
 
d078dc8
8db07f9
 
 
 
 
d078dc8
 
8db07f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# app.py
import streamlit as st
from PIL import Image
import torch
from torchvision import transforms
from transformers import AutoModelForImageClassification, AutoTokenizer
import os
from transformers import AutoModel
model = AutoModel.from_pretrained("rameye/1")

# Define the class labels
class_labels = {
    0: "Healthy eyes",
    1: "Mild DR",
    2: "Moderate DR",
    3: "NPDR",
    4: "Severe DR",
    5: "Glaucoma",
    6: "AMD",
    7: "Hypertensive retinopathy"
}

# Load the model and tokenizer from the Hugging Face model hub

# model = AutoModelForImageClassification.from_pretrained(model_name)

# tokenizer = AutoTokenizer.from_pretrained(model_name)

# Load model directly


# Load the model with the access token passed as an environment variable
# model_name = "your_model_name_in_hugging_face"
# model = AutoModelForImageClassification.from_pretrained(model_name)
model = AutoModel.from_pretrained("rameye/1")
tokenizer = AutoTokenizer.from_pretrained(model)



# Define image transformations
transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])

# Function to make predictions
def predict(image):
    image = transform(image).unsqueeze(0)
    with torch.no_grad():
        outputs = model(image)
    predicted_class = torch.argmax(outputs.logits).item()
    return class_labels[predicted_class]

# Streamlit UI
def main():
    st.title("Image Classifier")
    st.write("Upload an image and I'll classify it.")

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

    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"):
            with st.spinner('Classifying...'):
                prediction = predict(image)
                st.success(f"Prediction: {prediction}")

if __name__ == "__main__":
    main()