File size: 4,277 Bytes
6761609
 
d3936d3
2be2dd9
 
97fbaec
2be2dd9
 
97fbaec
2be2dd9
d3936d3
 
 
 
 
 
ceb5124
d3936d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b7cb87
70a53ec
b054b53
 
 
9bd7437
 
b054b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3936d3
dd931ae
d3936d3
2bbbf43
d3936d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
import streamlit as st

# Force immediate render on Hugging Face
st.set_page_config(page_title="COVID-19 AI System", layout="centered")
st.title("🧠 COVID-19 AI Dashboard")
st.write("Initializing app... Please use the sidebar to select a module.")

# Now import other things
import pandas as pd
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import matplotlib.pyplot as plt


# ------------------------- PAGE CONFIG -------------------------

# ------------------------- SIDEBAR -------------------------
st.sidebar.title("🧠 COVID-19 AI Dashboard")
app_mode = st.sidebar.radio("πŸ“ Select Module", ["🏠 Home", "🩻 X-ray Classifier", "πŸ“Š Global Data Analysis"])

# ------------------------- CUSTOM CSS -------------------------
st.markdown("""
    <style>
        .main { background-color: #f7f7f7; padding: 20px; border-radius: 10px; }
        .title { text-align: center; font-size: 36px; color: #4A90E2; font-weight: bold; }
        .subtitle { text-align: center; font-size: 18px; color: #444; }
    </style>
""", unsafe_allow_html=True)

# ------------------------- HOME PAGE -------------------------
if app_mode == "🏠 Home":
    st.markdown('<div class="main"><div class="title">COVID-19 Detection & Analysis</div><div class="subtitle">An integrated AI system using Deep Learning and WHO data</div></div>', unsafe_allow_html=True)
    st.write("Welcome to the COVID-19 AI dashboard. Use the sidebar to navigate between modules:")

    st.markdown("""
    - 🩻 **X-ray Classifier**: Upload a chest X-ray to detect COVID-19 using a deep learning model.
    - πŸ“Š **Global Data Analysis**: Explore real-world trends using WHO global COVID-19 dataset.
    """)

# ------------------------- X-RAY PREDICTION -------------------------
elif app_mode == "🩻 X-ray Classifier":
    st.header("🩺 Chest X-ray COVID Prediction")

    uploaded_image = st.file_uploader("πŸ“€ Upload Chest X-ray", type=["jpg", "jpeg", "png"])

    if uploaded_image:
        with st.spinner("πŸ” Predicting..."):
            try:
                # βœ… Load model from local models/ folder (no download, no 403 error)
                model = load_model("models/covid_xray_model.keras")
                st.success("βœ… Model loaded successfully!")
    
                # βœ… Process image and predict
                img = image.load_img(uploaded_image, target_size=(224, 224))
                img_array = image.img_to_array(img) / 255.0
                img_array = np.expand_dims(img_array, axis=0)
    
                pred = model.predict(img_array)[0]
                labels = ['COVID', 'NORMAL', 'Viral Pneumonia']
                result = labels[np.argmax(pred)]
    
                col1, col2 = st.columns([1, 2])
                with col1:
                    st.image(uploaded_image, caption="Uploaded X-ray", use_container_width=True)
                with col2:
                    st.success(f"🧠 **Predicted Condition:** `{result}`")
    
            except Exception as e:
                st.error(f"🚫 Prediction failed. Error: `{e}`")




# ------------------------- DATA ANALYSIS -------------------------
elif app_mode == "πŸ“Š Global Data Analysis":
    st.header("πŸ“Š WHO COVID-19 Data Analysis")

    df = pd.read_csv("WHO-COVID-19-global-data.csv")
    df["Date_reported"] = pd.to_datetime(df["Date_reported"])

    top_countries = df.groupby("Country")["New_cases"].sum().sort_values(ascending=False).head(10)

    st.subheader("🌍 Top 10 Countries by Total Reported Cases")
    st.bar_chart(top_countries)

    st.subheader("πŸ“ˆ Trend for Selected Country")
    selected_country = st.selectbox("Choose a country", df["Country"].unique())
    country_data = df[df["Country"] == selected_country]

    col1, col2 = st.columns(2)
    with col1:
        st.markdown("**Daily New Cases**")
        st.line_chart(country_data.set_index("Date_reported")[["New_cases"]])
    with col2:
        st.markdown("**Cumulative Cases Over Time**")
        st.line_chart(country_data.set_index("Date_reported")[["Cumulative_cases"]])

    with st.expander("πŸ“„ Show Raw Data"):
        st.dataframe(country_data.tail(10))