nehda10 commited on
Commit
d3936d3
Β·
verified Β·
1 Parent(s): f3f1444

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -83
app.py CHANGED
@@ -1,83 +1,82 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import numpy as np
4
- from tensorflow.keras.models import load_model
5
- from tensorflow.keras.preprocessing import image
6
- import matplotlib.pyplot as plt
7
-
8
- # ------------------------- PAGE CONFIG -------------------------
9
- st.set_page_config(page_title="COVID-19 AI System", layout="centered")
10
-
11
- # ------------------------- SIDEBAR -------------------------
12
- st.sidebar.image("https://i.imgur.com/NbA3RfI.png", use_container_width=True) # Optional: Replace with your own logo
13
- st.sidebar.title("🧠 COVID-19 AI Dashboard")
14
- app_mode = st.sidebar.radio("πŸ“ Select Module", ["🏠 Home", "🩻 X-ray Classifier", "πŸ“Š Global Data Analysis"])
15
-
16
- # ------------------------- CUSTOM CSS -------------------------
17
- st.markdown("""
18
- <style>
19
- .main { background-color: #f7f7f7; padding: 20px; border-radius: 10px; }
20
- .title { text-align: center; font-size: 36px; color: #4A90E2; font-weight: bold; }
21
- .subtitle { text-align: center; font-size: 18px; color: #444; }
22
- </style>
23
- """, unsafe_allow_html=True)
24
-
25
- # ------------------------- HOME PAGE -------------------------
26
- if app_mode == "🏠 Home":
27
- 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)
28
- st.write("Welcome to the COVID-19 AI dashboard. Use the sidebar to navigate between modules:")
29
-
30
- st.markdown("""
31
- - 🩻 **X-ray Classifier**: Upload a chest X-ray to detect COVID-19 using a deep learning model.
32
- - πŸ“Š **Global Data Analysis**: Explore real-world trends using WHO global COVID-19 dataset.
33
- """)
34
-
35
- # ------------------------- X-RAY PREDICTION -------------------------
36
- elif app_mode == "🩻 X-ray Classifier":
37
- st.header("🩺 Chest X-ray COVID Prediction")
38
-
39
- uploaded_image = st.file_uploader("πŸ“€ Upload Chest X-ray", type=["jpg", "jpeg", "png"])
40
-
41
- if uploaded_image:
42
- with st.spinner("πŸ” Predicting..."):
43
- model = load_model("covid_xray_model.keras")
44
- img = image.load_img(uploaded_image, target_size=(224, 224))
45
- img_array = image.img_to_array(img) / 255.0
46
- img_array = np.expand_dims(img_array, axis=0)
47
-
48
- pred = model.predict(img_array)[0]
49
- labels = ['COVID', 'NORMAL', 'Viral Pneumonia']
50
- result = labels[np.argmax(pred)]
51
-
52
- col1, col2 = st.columns([1, 2])
53
- with col1:
54
- st.image(uploaded_image, caption="Uploaded X-ray", use_container_width=True)
55
- with col2:
56
- st.success(f"🧠 **Predicted Condition:** `{result}`")
57
-
58
- # ------------------------- DATA ANALYSIS -------------------------
59
- elif app_mode == "πŸ“Š Global Data Analysis":
60
- st.header("πŸ“Š WHO COVID-19 Data Analysis")
61
-
62
- df = pd.read_csv("WHO-COVID-19-global-data.csv")
63
- df["Date_reported"] = pd.to_datetime(df["Date_reported"])
64
-
65
- top_countries = df.groupby("Country")["New_cases"].sum().sort_values(ascending=False).head(10)
66
-
67
- st.subheader("🌍 Top 10 Countries by Total Reported Cases")
68
- st.bar_chart(top_countries)
69
-
70
- st.subheader("πŸ“ˆ Trend for Selected Country")
71
- selected_country = st.selectbox("Choose a country", df["Country"].unique())
72
- country_data = df[df["Country"] == selected_country]
73
-
74
- col1, col2 = st.columns(2)
75
- with col1:
76
- st.markdown("**Daily New Cases**")
77
- st.line_chart(country_data.set_index("Date_reported")[["New_cases"]])
78
- with col2:
79
- st.markdown("**Cumulative Cases Over Time**")
80
- st.line_chart(country_data.set_index("Date_reported")[["Cumulative_cases"]])
81
-
82
- with st.expander("πŸ“„ Show Raw Data"):
83
- st.dataframe(country_data.tail(10))
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from tensorflow.keras.models import load_model
5
+ from tensorflow.keras.preprocessing import image
6
+ import matplotlib.pyplot as plt
7
+
8
+ # ------------------------- PAGE CONFIG -------------------------
9
+ st.set_page_config(page_title="COVID-19 AI System", layout="centered")
10
+
11
+ # ------------------------- SIDEBAR -------------------------
12
+ st.sidebar.title("🧠 COVID-19 AI Dashboard")
13
+ app_mode = st.sidebar.radio("πŸ“ Select Module", ["🏠 Home", "🩻 X-ray Classifier", "πŸ“Š Global Data Analysis"])
14
+
15
+ # ------------------------- CUSTOM CSS -------------------------
16
+ st.markdown("""
17
+ <style>
18
+ .main { background-color: #f7f7f7; padding: 20px; border-radius: 10px; }
19
+ .title { text-align: center; font-size: 36px; color: #4A90E2; font-weight: bold; }
20
+ .subtitle { text-align: center; font-size: 18px; color: #444; }
21
+ </style>
22
+ """, unsafe_allow_html=True)
23
+
24
+ # ------------------------- HOME PAGE -------------------------
25
+ if app_mode == "🏠 Home":
26
+ 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)
27
+ st.write("Welcome to the COVID-19 AI dashboard. Use the sidebar to navigate between modules:")
28
+
29
+ st.markdown("""
30
+ - 🩻 **X-ray Classifier**: Upload a chest X-ray to detect COVID-19 using a deep learning model.
31
+ - πŸ“Š **Global Data Analysis**: Explore real-world trends using WHO global COVID-19 dataset.
32
+ """)
33
+
34
+ # ------------------------- X-RAY PREDICTION -------------------------
35
+ elif app_mode == "🩻 X-ray Classifier":
36
+ st.header("🩺 Chest X-ray COVID Prediction")
37
+
38
+ uploaded_image = st.file_uploader("πŸ“€ Upload Chest X-ray", type=["jpg", "jpeg", "png"])
39
+
40
+ if uploaded_image:
41
+ with st.spinner("πŸ” Predicting..."):
42
+ model = load_model("covid_xray_model.keras")
43
+ img = image.load_img(uploaded_image, target_size=(224, 224))
44
+ img_array = image.img_to_array(img) / 255.0
45
+ img_array = np.expand_dims(img_array, axis=0)
46
+
47
+ pred = model.predict(img_array)[0]
48
+ labels = ['COVID', 'NORMAL', 'Viral Pneumonia']
49
+ result = labels[np.argmax(pred)]
50
+
51
+ col1, col2 = st.columns([1, 2])
52
+ with col1:
53
+ st.image(uploaded_image, caption="Uploaded X-ray", use_container_width=True)
54
+ with col2:
55
+ st.success(f"🧠 **Predicted Condition:** `{result}`")
56
+
57
+ # ------------------------- DATA ANALYSIS -------------------------
58
+ elif app_mode == "πŸ“Š Global Data Analysis":
59
+ st.header("πŸ“Š WHO COVID-19 Data Analysis")
60
+
61
+ df = pd.read_csv("WHO-COVID-19-global-data.csv")
62
+ df["Date_reported"] = pd.to_datetime(df["Date_reported"])
63
+
64
+ top_countries = df.groupby("Country")["New_cases"].sum().sort_values(ascending=False).head(10)
65
+
66
+ st.subheader("🌍 Top 10 Countries by Total Reported Cases")
67
+ st.bar_chart(top_countries)
68
+
69
+ st.subheader("πŸ“ˆ Trend for Selected Country")
70
+ selected_country = st.selectbox("Choose a country", df["Country"].unique())
71
+ country_data = df[df["Country"] == selected_country]
72
+
73
+ col1, col2 = st.columns(2)
74
+ with col1:
75
+ st.markdown("**Daily New Cases**")
76
+ st.line_chart(country_data.set_index("Date_reported")[["New_cases"]])
77
+ with col2:
78
+ st.markdown("**Cumulative Cases Over Time**")
79
+ st.line_chart(country_data.set_index("Date_reported")[["Cumulative_cases"]])
80
+
81
+ with st.expander("πŸ“„ Show Raw Data"):
82
+ st.dataframe(country_data.tail(10))