Spaces:
Runtime error
Runtime error
File size: 1,661 Bytes
0455f13 |
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 |
# app.py
import streamlit as st
from PIL import Image
import torch
from transformers import AutoImageProcessor, AutoModelForImageClassification
# App title and instructions
st.set_page_config(page_title="Skin Condition Classifier", layout="centered")
st.title("π§ AI Skin Condition Classifier")
st.markdown("Upload a **clear photo** of the skin condition to receive AI-powered predictions.")
# Image uploader
uploaded_file = st.file_uploader("π· Upload a skin image", type=["jpg", "jpeg", "png"])
# Load the pre-trained model
@st.cache_resource
def load_model():
model_name = "Anwarkh1/Skin_Cancer-Image_Classification"
processor = AutoImageProcessor.from_pretrained(model_name)
model = AutoModelForImageClassification.from_pretrained(model_name)
return processor, model
processor, model = load_model()
# Handle image upload and prediction
if uploaded_file is not None:
image = Image.open(uploaded_file).convert("RGB")
st.image(image, caption="Uploaded Image", use_column_width=True)
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=1)[0]
# Top 3 predictions
top_probs, top_indices = torch.topk(probs, k=3)
class_labels = model.config.id2label
st.subheader("π§Ύ Prediction Results")
for idx, prob in zip(top_indices, top_probs):
label = class_labels[idx.item()]
st.write(f"**{label}** β {prob.item() * 100:.2f}%")
st.info("π Note: This tool is for supportive use only. Please consult a dermatologist for a medical diagnosis.")
|