ad
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657# app.pyimport streamlit as stfrom PIL import Imageimport torchfrom torchvision import transformsfrom transformers import AutoModelForImageClassification, AutoTokenizer
# Define the class labelsclass_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 hubmodel_name = "m_64gb.pth"model = AutoModelForImageClassification.from_pretrained(model_name)tokenizer = AutoTokenizer.from_pretrained(model_name)
# Define image transformationstransform = 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 predictionsdef 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 UIdef 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()app.pyAdded+57