""" ================================================================= DERMASCAN-AI — Professional Medical UI Production Grade Healthcare Interface ================================================================= """ import json import streamlit as st import requests from PIL import Image from pathlib import Path # Import components from components.header import render_header from components.sidebar import render_sidebar from components.result_card import render_severity_banner, render_metrics, TIER_ICONS from components.confidence_chart import render_confidence_chart from components.care_advice_card import render_care_advice from components.hospital_map import render_hospital_map # ═══════════════════════════════════════════════════════════ # PAGE CONFIG # ═══════════════════════════════════════════════════════════ st.set_page_config( page_title="DermaScan AI | Advanced Dermatology Analysis", page_icon="🏥", layout="wide", initial_sidebar_state="expanded", ) API_URL = "http://localhost:8000" # ═══════════════════════════════════════════════════════════ # LOAD EXTERNAL DATA & STYLES # ═══════════════════════════════════════════════════════════ config_dir = Path(__file__).parent.parent / "configs" with open(config_dir / "india_cities.json", "r", encoding="utf-8") as f: STATE_CITIES = json.load(f) # Load CSS css_file = Path(__file__).parent / "assets" / "style.css" with open(css_file, "r", encoding="utf-8") as f: st.markdown(f"", unsafe_allow_html=True) # Remove tooltips with JavaScript st.markdown(""" """, unsafe_allow_html=True) # ═══════════════════════════════════════════════════════════ # SIDEBAR # ═══════════════════════════════════════════════════════════ selected_state, selected_city = render_sidebar(STATE_CITIES) # ═══════════════════════════════════════════════════════════ # HEADER # ═══════════════════════════════════════════════════════════ render_header() # ═══════════════════════════════════════════════════════════ # UPLOAD SECTION # ═══════════════════════════════════════════════════════════ uploaded_file = st.file_uploader( "Upload a skin image for analysis", type=["jpg", "jpeg", "png"], ) if uploaded_file: img_col, action_col = st.columns([1, 2]) with img_col: image = Image.open(uploaded_file) st.markdown('
', unsafe_allow_html=True) st.image(image, caption="📸 Uploaded Image", width="stretch") st.markdown('
', unsafe_allow_html=True) with action_col: st.markdown(f"**📍 Location:** {selected_city}, {selected_state}") st.markdown("") analyze = st.button("🔬 Analyze Image", width="stretch") if analyze: with st.spinner("🔄 Analyzing your image with AI..."): try: files = { "file": ( uploaded_file.name, uploaded_file.getvalue(), uploaded_file.type, ) } params = {"city": selected_city, "state": selected_state} resp = requests.post( f"{API_URL}/predict", files=files, params=params, timeout=60, ) if resp.status_code == 200: st.session_state["result"] = resp.json() st.success("✅ Analysis complete!") st.rerun() else: st.error(f"❌ Server error: {resp.text}") except requests.exceptions.ConnectionError: st.error( "⚠️ Cannot connect to API server. " "Open another terminal and run: `python -m api.app`" ) st.markdown("""

💡 Tips for Best Results

✓ Use a clear, well-lit close-up photo
✓ Center the affected area in the frame
✓ Keep camera 10-15 cm from the skin
✓ Avoid shadows and reflections
✓ Use natural lighting when possible

""", unsafe_allow_html=True) # ═══════════════════════════════════════════════════════════ # RESULTS SECTION # ═══════════════════════════════════════════════════════════ if "result" in st.session_state: result = st.session_state["result"] st.markdown("---") # Severity Banner render_severity_banner(result) # Key Metrics render_metrics(result) # Cancer Warning cancer_warning = result.get("cancer_warning", "") if cancer_warning: st.markdown( f'
' f'
⚠️
' f"
MEDICAL ALERT: {cancer_warning}
" f"
", unsafe_allow_html=True, ) # Tabs tab1, tab2, tab3, tab4 = st.tabs( ["📋 Diagnosis", "📊 Confidence Analysis", "💊 Care Advice", "🏥 Find Hospitals"] ) # Tab 1: Diagnosis with tab1: st.markdown( f'
' f'

🔬 {result["predicted_class"]}

' f'

{result.get("description", "")}

' f'

' f'⏰ {result.get("urgency_message", "")}

' f"
", unsafe_allow_html=True, ) st.markdown( f'
' f"

🎯 AI Confidence Assessment

" f'

{result.get("confidence_message", "")}

' f"
", unsafe_allow_html=True, ) diff = result.get("differential_diagnosis", []) if len(diff) > 1: diff_html = '

🔍 Differential Diagnosis

' diff_html += '

Other possible conditions to consider:

' for d in diff: d_icon = TIER_ICONS.get(d.get("tier", ""), "⚪") d_prob = d.get("probability", 0) diff_html += ( f'
' f'
{d_icon}
' f'
{d["class_name"]} — Probability: {d_prob:.1%}
' f"
" ) diff_html += "
" st.markdown(diff_html, unsafe_allow_html=True) # Tab 2: Confidence Chart with tab2: render_confidence_chart(result) # Tab 3: Care Advice with tab3: render_care_advice(result) # Tab 4: Hospitals with tab4: render_hospital_map(result, selected_city, selected_state) # Disclaimer disclaimer = result.get( "disclaimer", "This is an AI tool for educational purposes only. " "Not a substitute for professional medical diagnosis.", ) st.markdown( f'
' f"⚕️ MEDICAL DISCLAIMER: {disclaimer}" f"
", unsafe_allow_html=True, ) inf_t = result.get("inference_time", 0) st.markdown( f'

' f'⚡ Analysis completed in {inf_t:.2f}s | 🧠 EfficientNet-B3 | 🏥 DermaScan AI v1.0' f'

', unsafe_allow_html=True ) elif not uploaded_file: st.markdown( '
' '
📸
' "

Upload a Skin Image to Begin Analysis

" "

Our advanced AI system will analyze the image, identify potential conditions, " "provide personalized care recommendations, and help you locate nearby medical facilities.

" "
", unsafe_allow_html=True, ) # ═══════════════════════════════════════════════════════════ # FOOTER # ═══════════════════════════════════════════════════════════ st.markdown("---") st.markdown( "

" "🏥 DermaScan AI | 🧠 EfficientNet-B3 Architecture | 📊 HAM10000 + DermNet Dataset
" "🔬 13 Skin Conditions | 🎯 96% AUC-ROC Accuracy | ⚡ Real-time Analysis
" "🛠️ Built with PyTorch • FastAPI • Streamlit
" "For educational and research purposes only. Not a substitute for professional medical advice." "

", unsafe_allow_html=True, )