Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,337 +1,336 @@
|
|
1 |
-
import os
|
2 |
-
import streamlit as st
|
3 |
-
from PIL import Image
|
4 |
-
import pandas as pd
|
5 |
-
from datetime import datetime
|
6 |
-
from transformers import (
|
7 |
-
AutoFeatureExtractor,
|
8 |
-
AutoModelForImageClassification,
|
9 |
-
AutoTokenizer,
|
10 |
-
AutoModelForSeq2SeqLM,
|
11 |
-
pipeline,
|
12 |
-
|
13 |
-
|
14 |
-
import
|
15 |
-
|
16 |
-
import
|
17 |
-
|
18 |
-
import
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
#
|
25 |
-
#
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
st.session_state['
|
38 |
-
st.session_state['
|
39 |
-
st.session_state['
|
40 |
-
st.session_state['
|
41 |
-
st.session_state['
|
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 |
-
df.
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
bgr =
|
132 |
-
bgr =
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
h, w
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
top, left =
|
146 |
-
canvas
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
st.
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
st.
|
165 |
-
|
166 |
-
|
167 |
-
raw =
|
168 |
-
|
169 |
-
|
170 |
-
proc =
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
'
|
193 |
-
'
|
194 |
-
'
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
loc
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
"
|
211 |
-
|
212 |
-
)
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
st.
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
gloc
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
user_q
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
f"{
|
238 |
-
|
239 |
-
)
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
prefix
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
df = pd.
|
254 |
-
df
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
sel
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
entries
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
st.
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
f"{row['
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
st.
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
'
|
305 |
-
'
|
306 |
-
'
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
st.
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
cols
|
325 |
-
|
326 |
-
|
327 |
-
img =
|
328 |
-
col.
|
329 |
-
|
330 |
-
|
331 |
-
st.sidebar.
|
332 |
-
st.sidebar.write("
|
333 |
-
st.sidebar.write(f"
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
st.write()
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from PIL import Image
|
4 |
+
import pandas as pd
|
5 |
+
from datetime import datetime
|
6 |
+
from transformers import (
|
7 |
+
AutoFeatureExtractor,
|
8 |
+
AutoModelForImageClassification,
|
9 |
+
AutoTokenizer,
|
10 |
+
AutoModelForSeq2SeqLM,
|
11 |
+
pipeline,
|
12 |
+
)
|
13 |
+
import requests
|
14 |
+
from geopy.geocoders import Nominatim
|
15 |
+
import folium
|
16 |
+
from streamlit_folium import st_folium
|
17 |
+
import cv2
|
18 |
+
import numpy as np
|
19 |
+
|
20 |
+
|
21 |
+
st.set_page_config(page_title="Skin Cancer Dashboard", layout="wide")
|
22 |
+
|
23 |
+
# --- Configuration ---
|
24 |
+
# Ensure you have set your Hugging Face token as an environment variable:
|
25 |
+
# export HF_TOKEN="YOUR_TOKEN_HERE"
|
26 |
+
MODEL_NAME = "Anwarkh1/Skin_Cancer-Image_Classification"
|
27 |
+
LLM_NAME = "google/flan-t5-xl"
|
28 |
+
HF_TOKEN = ".."
|
29 |
+
DATA_DIR = "data/harvard_dataset" # Path where you download and unpack the Harvard Dataverse dataset
|
30 |
+
DIARY_CSV = "diary.csv"
|
31 |
+
CANCER_DIR = r"D:\Models\googleflan-t5-xl"
|
32 |
+
LLM_DIR = r"D:\Models\SkinCancer"
|
33 |
+
|
34 |
+
# Initialize session state defaults
|
35 |
+
if 'initialized' not in st.session_state:
|
36 |
+
st.session_state['label'] = None
|
37 |
+
st.session_state['score'] = None
|
38 |
+
st.session_state['mole_id'] = ''
|
39 |
+
st.session_state['geo_location'] = ''
|
40 |
+
st.session_state['chat_history'] = []
|
41 |
+
st.session_state['initialized'] = True
|
42 |
+
|
43 |
+
# Initialize geolocator for free geocoding
|
44 |
+
geolocator = Nominatim(user_agent="skin-dashboard", timeout = 10)
|
45 |
+
|
46 |
+
# --- Load Model & Feature Extractor ---
|
47 |
+
@st.cache_resource
|
48 |
+
def load_image_model(token: str):
|
49 |
+
extractor = AutoFeatureExtractor.from_pretrained(
|
50 |
+
MODEL_NAME,
|
51 |
+
use_auth_token=token
|
52 |
+
)
|
53 |
+
model = AutoModelForImageClassification.from_pretrained(
|
54 |
+
MODEL_NAME,
|
55 |
+
use_auth_token=token
|
56 |
+
)
|
57 |
+
return pipeline(
|
58 |
+
"image-classification",
|
59 |
+
model=model,
|
60 |
+
feature_extractor=extractor,
|
61 |
+
device=0 # set to GPU index or -1 for CPU
|
62 |
+
)
|
63 |
+
|
64 |
+
@st.cache_resource
|
65 |
+
def load_llm(token: str):
|
66 |
+
|
67 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
68 |
+
LLM_NAME,
|
69 |
+
use_auth_token=token
|
70 |
+
)
|
71 |
+
# Use Seq2SeqLM for T5-style (text2text) models:
|
72 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(
|
73 |
+
LLM_NAME,
|
74 |
+
use_auth_token=token,
|
75 |
+
)
|
76 |
+
return pipeline(
|
77 |
+
"text2text-generation",
|
78 |
+
model=model,
|
79 |
+
tokenizer=tokenizer,
|
80 |
+
device_map="auto", # or device=0 for single GPU / -1 for CPU
|
81 |
+
max_length=10000,
|
82 |
+
num_beams=5,
|
83 |
+
no_repeat_ngram_size=2,
|
84 |
+
early_stopping=True,
|
85 |
+
|
86 |
+
)
|
87 |
+
classifier = load_image_model(HF_TOKEN) if HF_TOKEN else None
|
88 |
+
explainer = load_llm(HF_TOKEN) if HF_TOKEN else None
|
89 |
+
|
90 |
+
# --- Diary Init ----
|
91 |
+
|
92 |
+
if not os.path.exists(DIARY_CSV):
|
93 |
+
pd.DataFrame(
|
94 |
+
columns=["timestamp", "image_path", "mole_id", "geo_location", "label", "score",
|
95 |
+
"body_location", "prior_consultation", "pain", "itch"]
|
96 |
+
).to_csv(DIARY_CSV, index=False)
|
97 |
+
|
98 |
+
# --- Save entry helper
|
99 |
+
|
100 |
+
def save_entry(img_path: str, mole_id: str, geo_location: str,
|
101 |
+
label: str, score: float,
|
102 |
+
body_location: str, prior_consult: str, pain: str, itch: str):
|
103 |
+
df = pd.read_csv(DIARY_CSV)
|
104 |
+
entry = {
|
105 |
+
"timestamp": datetime.now().isoformat(),
|
106 |
+
"image_path": img_path,
|
107 |
+
"mole_id": mole_id,
|
108 |
+
"geo_location": geo_location,
|
109 |
+
"label": label,
|
110 |
+
"score": float(score),
|
111 |
+
"body_location": body_location,
|
112 |
+
"prior_consultation": prior_consult,
|
113 |
+
"pain": pain,
|
114 |
+
"itch": itch
|
115 |
+
}
|
116 |
+
df.loc[len(df)] = entry
|
117 |
+
df.to_csv(DIARY_CSV, index=False)
|
118 |
+
|
119 |
+
# --- Preprocessing Functions ---
|
120 |
+
def remove_hair(img: np.ndarray) -> np.ndarray:
|
121 |
+
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
122 |
+
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (17, 17))
|
123 |
+
blackhat = cv2.morphologyEx(gray, cv2.MORPH_BLACKHAT, kernel)
|
124 |
+
_, mask = cv2.threshold(blackhat, 10, 255, cv2.THRESH_BINARY)
|
125 |
+
return cv2.inpaint(img, mask, 1, cv2.INPAINT_TELEA)
|
126 |
+
|
127 |
+
|
128 |
+
def preprocess(img: Image.Image, size: int = 224) -> Image.Image:
|
129 |
+
arr = np.array(img)
|
130 |
+
bgr = cv2.cvtColor(arr, cv2.COLOR_RGB2BGR)
|
131 |
+
bgr = remove_hair(bgr)
|
132 |
+
bgr = cv2.bilateralFilter(bgr, d=9, sigmaColor=75, sigmaSpace=75)
|
133 |
+
lab = cv2.cvtColor(bgr, cv2.COLOR_BGR2LAB)
|
134 |
+
l, a, b = cv2.split(lab)
|
135 |
+
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
|
136 |
+
cl = clahe.apply(l)
|
137 |
+
merged = cv2.merge((cl, a, b))
|
138 |
+
bgr = cv2.cvtColor(merged, cv2.COLOR_LAB2BGR)
|
139 |
+
h, w = bgr.shape[:2]
|
140 |
+
scale = size / max(h, w)
|
141 |
+
nh, nw = int(h*scale), int(w*scale)
|
142 |
+
resized = cv2.resize(bgr, (nw, nh), interpolation=cv2.INTER_AREA)
|
143 |
+
canvas = np.full((size, size, 3), 128, dtype=np.uint8)
|
144 |
+
top, left = (size-nh)//2, (size-nw)//2
|
145 |
+
canvas[top:top+nh, left:left+nw] = resized
|
146 |
+
rgb = cv2.cvtColor(canvas, cv2.COLOR_BGR2RGB)
|
147 |
+
return Image.fromarray(rgb)
|
148 |
+
|
149 |
+
# -----Streamlit layout ----
|
150 |
+
st.title("🩺 Skin Cancer Recognition Dashboard")
|
151 |
+
menu = ["Scan Mole","Chat","Diary", "Dataset Explorer"]
|
152 |
+
choice = st.sidebar.selectbox("Navigation", menu)
|
153 |
+
|
154 |
+
# --- Initialize Scan a Mole ---
|
155 |
+
if choice == "Scan Mole":
|
156 |
+
st.header("🔍 Scan a Mole")
|
157 |
+
if not classifier:
|
158 |
+
st.error("Missing HF_TOKEN.")
|
159 |
+
st.stop()
|
160 |
+
|
161 |
+
upload = st.file_uploader("Upload a skin image", type=["jpg","jpeg","png"])
|
162 |
+
if not upload:
|
163 |
+
st.info("Please upload an image to begin.")
|
164 |
+
st.stop()
|
165 |
+
|
166 |
+
raw = Image.open(upload).convert("RGB")
|
167 |
+
st.image(raw, caption="Original", use_container_width=True)
|
168 |
+
|
169 |
+
proc = preprocess(raw)
|
170 |
+
st.image(proc, caption="Preprocessed", use_container_width=True)
|
171 |
+
|
172 |
+
mole = st.text_input("Mole ID")
|
173 |
+
city = st.text_input("Geographic location")
|
174 |
+
body = st.selectbox("Body location", ["Face","Scalp","Neck","Chest","Back","Arm","Hand","Leg","Foot","Other"])
|
175 |
+
prior = st.radio("Prior consult?", ["Yes","No"], horizontal=True)
|
176 |
+
pain = st.radio("Pain?", ["Yes","No"], horizontal=True)
|
177 |
+
itch = st.radio("Itch?", ["Yes","No"], horizontal=True)
|
178 |
+
|
179 |
+
if st.button("Classify"):
|
180 |
+
if not mole or not city:
|
181 |
+
st.error("Enter ID and location.")
|
182 |
+
else:
|
183 |
+
with st.spinner("Analyzing..."):
|
184 |
+
out = classifier(proc)
|
185 |
+
lbl, scr = out[0]["label"], out[0]["score"]
|
186 |
+
save_dir = os.path.join("scans", f"{mole}_{datetime.now().timestamp()}.png")
|
187 |
+
os.makedirs(os.path.dirname(save_dir), exist_ok=True)
|
188 |
+
raw.save(save_dir)
|
189 |
+
save_entry(save_dir, mole, city, lbl, scr, body, prior, pain, itch)
|
190 |
+
st.session_state.update({
|
191 |
+
'label': lbl,
|
192 |
+
'score': scr,
|
193 |
+
'mole_id': mole,
|
194 |
+
'geo_location': city
|
195 |
+
})
|
196 |
+
|
197 |
+
if st.session_state['label']:
|
198 |
+
st.success(f"Prediction: {st.session_state['label']} (score {st.session_state['score']:.2f})")
|
199 |
+
if explainer:
|
200 |
+
with st.spinner("Explaining..."):
|
201 |
+
text = explainer(f"Explain {st.session_state['label']} and recommendation.")[0]['generated_text']
|
202 |
+
st.markdown("### Explanation"); st.write(text)
|
203 |
+
|
204 |
+
loc = geolocator.geocode(st.session_state['geo_location'])
|
205 |
+
if loc:
|
206 |
+
m = folium.Map([loc.latitude, loc.longitude], zoom_start=12)
|
207 |
+
folium.Marker([loc.latitude, loc.longitude], "You").add_to(m)
|
208 |
+
resp = requests.post(
|
209 |
+
"https://overpass-api.de/api/interpreter",
|
210 |
+
data={"data": f"[out:json];node(around:5000,{loc.latitude},{loc.longitude})[~\"^(amenity|healthcare)$\"~\"clinic|doctors\"];out;"}
|
211 |
+
)
|
212 |
+
for el in resp.json().get('elements', []):
|
213 |
+
tags = el.get('tags', {});
|
214 |
+
lat = el.get('lat') or el['center']['lat']; lon = el.get('lon') or el['center']['lon']
|
215 |
+
folium.Marker([lat, lon], tags.get('name','Clinic')).add_to(m)
|
216 |
+
st.markdown("### Nearby Clinics"); st_folium(m, width=700)
|
217 |
+
|
218 |
+
# --- Chat Tab ---
|
219 |
+
elif choice == "Chat":
|
220 |
+
st.header("💬 Follow-Up Chat")
|
221 |
+
if not st.session_state['label']:
|
222 |
+
st.info("Please perform a scan first in the 'Scan Mole' tab.")
|
223 |
+
else:
|
224 |
+
lbl = st.session_state['label']
|
225 |
+
scr = st.session_state['score']
|
226 |
+
mid = st.session_state['mole_id']
|
227 |
+
gloc = st.session_state['geo_location']
|
228 |
+
st.markdown(f"**Context:** prediction for **{mid}** at **{gloc}** is **{lbl}** (confidence {scr:.2f}).")
|
229 |
+
|
230 |
+
# New user message comes first for immediate loop
|
231 |
+
user_q = st.chat_input("Ask a follow-up question:", key="chat_input")
|
232 |
+
if user_q and explainer:
|
233 |
+
st.session_state['chat_history'].append({'role':'user','content':user_q})
|
234 |
+
system_p = "You are a dermatology assistant. Provide concise medical advice without clarifying questions."
|
235 |
+
tpl = (
|
236 |
+
f"{system_p}\nContext: prediction is {lbl} with confidence {scr:.2f}.\n"
|
237 |
+
f"User: {user_q}\nAssistant:"
|
238 |
+
)
|
239 |
+
with st.spinner("Generating response..."):
|
240 |
+
reply = explainer(tpl)[0]['generated_text']
|
241 |
+
st.session_state['chat_history'].append({'role':'assistant','content':reply})
|
242 |
+
|
243 |
+
# Display the updated chat history
|
244 |
+
for msg in st.session_state['chat_history']:
|
245 |
+
prefix = 'You' if msg['role']=='user' else 'AI'
|
246 |
+
st.markdown(f"**{prefix}:** {msg['content']}")
|
247 |
+
|
248 |
+
|
249 |
+
# --- Diary Page ---
|
250 |
+
elif choice == "Diary":
|
251 |
+
st.header("📖 Skin Cancer Diary")
|
252 |
+
df = pd.read_csv(DIARY_CSV)
|
253 |
+
df['timestamp'] = pd.to_datetime(df['timestamp'])
|
254 |
+
if df.empty:
|
255 |
+
st.info("No diary entries yet.")
|
256 |
+
else:
|
257 |
+
mole_ids = sorted(df['mole_id'].unique())
|
258 |
+
sel = st.selectbox("Select Mole to View", ['All'] + mole_ids, key="diary_sel")
|
259 |
+
if sel == 'All':
|
260 |
+
# Display moles in columns (max 3 per row)
|
261 |
+
chunks = [mole_ids[i:i+3] for i in range(0, len(mole_ids), 3)]
|
262 |
+
for group in chunks:
|
263 |
+
cols = st.columns(len(group))
|
264 |
+
for col, mid in zip(cols, group):
|
265 |
+
with col:
|
266 |
+
st.subheader(mid)
|
267 |
+
entries = df[df['mole_id'] == mid].sort_values('timestamp')
|
268 |
+
# Show image timeline
|
269 |
+
for _, row in entries.iterrows():
|
270 |
+
if os.path.exists(row['image_path']):
|
271 |
+
st.image(
|
272 |
+
row['image_path'],
|
273 |
+
width=150,
|
274 |
+
caption=f"{row['timestamp'].strftime('%Y-%m-%d')} — {row['score']:.2f}"
|
275 |
+
)
|
276 |
+
st.write(f"Total scans: {len(entries)}")
|
277 |
+
else:
|
278 |
+
# Detailed view for a single mole
|
279 |
+
entries = df[df['mole_id'] == sel].sort_values('timestamp')
|
280 |
+
if entries.empty:
|
281 |
+
st.warning(f"No entries for {sel}.")
|
282 |
+
else:
|
283 |
+
# Score over time
|
284 |
+
st.line_chart(entries.set_index('timestamp')['score'])
|
285 |
+
st.markdown("#### Image Timeline")
|
286 |
+
for _, row in entries.iterrows():
|
287 |
+
if os.path.exists(row['image_path']):
|
288 |
+
st.image(
|
289 |
+
row['image_path'],
|
290 |
+
width=200,
|
291 |
+
caption=(
|
292 |
+
f"{row['timestamp'].strftime('%Y-%m-%d %H:%M')} — "
|
293 |
+
f"Score: {row['score']:.2f}"
|
294 |
+
)
|
295 |
+
)
|
296 |
+
st.markdown("#### Details")
|
297 |
+
st.dataframe(
|
298 |
+
entries[
|
299 |
+
['timestamp','geo_location','label','score',
|
300 |
+
'body_location','prior_consultation','pain','itch']
|
301 |
+
]
|
302 |
+
.rename(columns={
|
303 |
+
'timestamp':'Time','geo_location':'Location',
|
304 |
+
'label':'Diagnosis','score':'Confidence',
|
305 |
+
'body_location':'Body Part','prior_consultation':'Prior Consult',
|
306 |
+
'pain':'Pain','itch':'Itch'
|
307 |
+
})
|
308 |
+
.sort_values('Time', ascending=False)
|
309 |
+
)
|
310 |
+
|
311 |
+
else:
|
312 |
+
st.header("📂 Dataset Explorer")
|
313 |
+
st.write("Preview images from the Harvard Skin Cancer Dataset")
|
314 |
+
|
315 |
+
# pick up to 15 image files
|
316 |
+
image_files = [
|
317 |
+
f for f in os.listdir(DATA_DIR)
|
318 |
+
if os.path.isfile(os.path.join(DATA_DIR, f))
|
319 |
+
and f.lower().endswith((".jpg", ".jpeg", ".png"))
|
320 |
+
][:15]
|
321 |
+
|
322 |
+
for i in range(0, len(image_files), 3):
|
323 |
+
cols = st.columns(3)
|
324 |
+
for col, fn in zip(cols, image_files[i : i + 3]):
|
325 |
+
path = os.path.join(DATA_DIR, fn)
|
326 |
+
img = Image.open(path)
|
327 |
+
col.image(img, use_container_width=True)
|
328 |
+
col.caption(fn)
|
329 |
+
|
330 |
+
st.sidebar.markdown("---")
|
331 |
+
st.sidebar.write("Dataset powered by Harvard Dataverse [DBW86T]")
|
332 |
+
st.sidebar.write(f"Model: {MODEL_NAME}")
|
333 |
+
st.sidebar.write(f"LLM: {LLM_NAME}")
|
334 |
+
|
335 |
+
if __name__ == '__main__':
|
336 |
+
st.write()
|
|