Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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.
|
| 13 |
-
st.sidebar.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
.
|
| 20 |
-
.
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
st.
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
img_array =
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
df = pd.
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
st.
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
st.
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
st.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
st.
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 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))
|
|
|