SuriRaja commited on
Commit
0455f13
·
verified ·
1 Parent(s): 4e508b0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import streamlit as st
4
+ from PIL import Image
5
+ import torch
6
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
7
+
8
+ # App title and instructions
9
+ st.set_page_config(page_title="Skin Condition Classifier", layout="centered")
10
+ st.title("🧠 AI Skin Condition Classifier")
11
+ st.markdown("Upload a **clear photo** of the skin condition to receive AI-powered predictions.")
12
+
13
+ # Image uploader
14
+ uploaded_file = st.file_uploader("📷 Upload a skin image", type=["jpg", "jpeg", "png"])
15
+
16
+ # Load the pre-trained model
17
+ @st.cache_resource
18
+ def load_model():
19
+ model_name = "Anwarkh1/Skin_Cancer-Image_Classification"
20
+ processor = AutoImageProcessor.from_pretrained(model_name)
21
+ model = AutoModelForImageClassification.from_pretrained(model_name)
22
+ return processor, model
23
+
24
+ processor, model = load_model()
25
+
26
+ # Handle image upload and prediction
27
+ if uploaded_file is not None:
28
+ image = Image.open(uploaded_file).convert("RGB")
29
+ st.image(image, caption="Uploaded Image", use_column_width=True)
30
+
31
+ inputs = processor(images=image, return_tensors="pt")
32
+ with torch.no_grad():
33
+ outputs = model(**inputs)
34
+
35
+ logits = outputs.logits
36
+ probs = torch.nn.functional.softmax(logits, dim=1)[0]
37
+
38
+ # Top 3 predictions
39
+ top_probs, top_indices = torch.topk(probs, k=3)
40
+ class_labels = model.config.id2label
41
+
42
+ st.subheader("🧾 Prediction Results")
43
+ for idx, prob in zip(top_indices, top_probs):
44
+ label = class_labels[idx.item()]
45
+ st.write(f"**{label}** – {prob.item() * 100:.2f}%")
46
+
47
+ st.info("🔍 Note: This tool is for supportive use only. Please consult a dermatologist for a medical diagnosis.")