File size: 4,598 Bytes
8be8858
 
 
5d58e79
06b57f4
8be8858
 
 
 
 
 
 
 
 
 
06b57f4
8be8858
 
 
 
 
5d58e79
8be8858
06b57f4
 
 
 
 
8be8858
 
 
 
5d58e79
8be8858
 
 
 
5d58e79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
06b57f4
8be8858
 
 
 
 
 
 
 
 
5d58e79
8be8858
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21436da
8be8858
5d58e79
8be8858
 
 
5d58e79
8be8858
 
 
21436da
8be8858
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17ec5d6
8be8858
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import streamlit as st
from transformers import pipeline
from PIL import Image
import requests

# =======================
# Caching the Model
# =======================
@st.cache_resource
def load_model():
    """
    Load the pre-trained skin cancer classification model.
    Cached to prevent reloading on every app interaction.
    """
    return pipeline("image-classification", model="Anwarkh1/Skin_Cancer-Image_Classification")

model = load_model()

# =======================
# Functionality: Classify Skin Cancer
# =======================
def classify_skin_cancer(image):
    results = model(image)
    label = results[0]['label']
    confidence = results[0]['score']
    explanation = f"The model predicts **{label}** with a confidence of {confidence:.2%}."
    return label, confidence, explanation

# =======================
# Functionality: Fetch Cancer Research Papers
# =======================
@st.cache_data
def fetch_cancer_research():
    """
    Fetch the latest research papers related to skin cancer.
    Cached to avoid repeated API calls.
    """
    api_url = "https://api.semanticscholar.org/graph/v1/paper/search"
    params = {
        "query": "skin cancer research",
        "fields": "title,abstract,url",
        "limit": 5
    }
    response = requests.get(api_url, params=params)
    if response.status_code == 200:
        papers = response.json().get("data", [])
        summaries = []
        for paper in papers:
            title = paper.get("title", "No Title")
            abstract = paper.get("abstract", "No Abstract")
            url = paper.get("url", "No URL")
            summaries.append(f"**{title}**\n\n{abstract}\n\n[Read More]({url})")
        return "\n\n---\n\n".join(summaries)
    else:
        return "Error fetching research papers. Please try again later."

# =======================
# Streamlit Page Config
# =======================
st.set_page_config(
    page_title="AI-Powered Skin Cancer Detection",
    page_icon="🩺",
    layout="wide",
    initial_sidebar_state="expanded"
)

st.sidebar.header("Navigation")
app_mode = st.sidebar.radio(
    "Choose a feature",
    ["πŸ” Skin Cancer Classification", "πŸ“„ Latest Research Papers", "ℹ️ About the Model"]
)

# =======================
# Skin Cancer Classification
# =======================
if app_mode == "πŸ” Skin Cancer Classification":
    st.title("πŸ” Skin Cancer Classification")
    st.write(
        "Upload an image of the skin lesion, and the AI model will classify it as one of several types, "
        "such as melanoma, basal cell carcinoma, or benign keratosis-like lesions."
    )

    uploaded_image = st.file_uploader("Upload a skin lesion image", type=["png", "jpg", "jpeg"])

    if uploaded_image:
        image = Image.open(uploaded_image).convert('RGB')
        st.image(image, caption="Uploaded Image", use_column_width=True)

        # Perform classification
        st.write("Classifying...")
        label, confidence, explanation = classify_skin_cancer(image)

        # Display results
        st.markdown(f"### **Prediction**: {label}")
        st.markdown(f"### **Confidence**: {confidence:.2%}")
        st.markdown(f"### **Explanation**: {explanation}")

# =======================
# Latest Research Papers
# =======================
elif app_mode == "πŸ“„ Latest Research Papers":
    st.title("πŸ“„ Latest Research Papers")
    st.write(
        "Fetch the latest research papers on skin cancer to stay updated on recent findings and innovations."
    )

    if st.button("Fetch Papers"):
        with st.spinner("Fetching research papers..."):
            summaries = fetch_cancer_research()
        st.markdown(summaries)

# =======================
# About the Model
# =======================
elif app_mode == "ℹ️ About the Model":
    st.title("ℹ️ About the Skin Cancer Detection Model")
    st.markdown("""
    - **Model Architecture:** Vision Transformer (ViT)  
    - **Trained On:** Skin Cancer Dataset (ISIC)  
    - **Classes:**  
      - Benign keratosis-like lesions  
      - Basal cell carcinoma  
      - Actinic keratoses  
      - Vascular lesions  
      - Melanocytic nevi  
      - Melanoma  
      - Dermatofibroma  
    - **Performance Metrics:**  
      - **Validation Accuracy:** 96.95%  
      - **Train Accuracy:** 96.14%  
    - **Loss Function:** Cross-Entropy  
    """)

# =======================
# Footer
# =======================
st.sidebar.info("""
Developed by **[mgbam](https://huggingface.co/mgbam)**  
This app leverages state-of-the-art AI models for skin cancer detection and research insights.
""")