Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,79 +1,56 @@
|
|
1 |
-
# import libraries
|
2 |
-
import os
|
3 |
-
from dotenv import load_dotenv
|
4 |
import streamlit as st
|
5 |
-
import
|
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 |
-
# Search answers from Vector DB
|
61 |
-
def retrieve_answer(query):
|
62 |
-
doc_search = retrieve_query(query)
|
63 |
-
chain = retrieval_qa_chain()
|
64 |
-
response = chain.run(input_documents=doc_search, question=query)
|
65 |
-
return response
|
66 |
-
|
67 |
-
queries = st.text_input('write a medical questions ?')
|
68 |
-
# Example usage
|
69 |
-
submit = st.button('submit')
|
70 |
-
# Read and process documents
|
71 |
-
# doc = read_doc('documents/')
|
72 |
-
# documents = chunk_data(docs=doc)
|
73 |
-
# create_index(documents)
|
74 |
-
if submit :
|
75 |
-
if queries :
|
76 |
-
# Query and get answer
|
77 |
-
#our_query = 'What is cause of Eczema?'
|
78 |
-
answer = retrieve_answer(queries)
|
79 |
-
st.write(answer)
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import seaborn as sns
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
|
6 |
+
# Load Data
|
7 |
+
@st.cache_data
|
8 |
+
def load_data():
|
9 |
+
return pd.read_csv("data/inbody_with_clusters.csv", parse_dates=["Test Date"])
|
10 |
+
|
11 |
+
df = load_data()
|
12 |
+
|
13 |
+
st.title("📊 InBody 270 Dashboard")
|
14 |
+
st.markdown("Explore trends, clusters, and body composition metrics.")
|
15 |
+
|
16 |
+
# Sidebar Filters
|
17 |
+
with st.sidebar:
|
18 |
+
st.header("🔎 Filter")
|
19 |
+
id_options = df['ID'].unique()
|
20 |
+
selected_ids = st.multiselect("Select Patient ID(s)", id_options, default=list(id_options[:5]))
|
21 |
+
|
22 |
+
gender = st.radio("Gender", options=["All", "M", "F"])
|
23 |
+
bmi_range = st.slider("BMI Range", float(df["27. BMI (Body Mass Index)"].min()),
|
24 |
+
float(df["27. BMI (Body Mass Index)"].max()), (18.5, 35.0))
|
25 |
+
|
26 |
+
# Apply Filters
|
27 |
+
filtered = df[df["ID"].isin(selected_ids)]
|
28 |
+
if gender != "All":
|
29 |
+
filtered = filtered[filtered["3. Gender"] == gender]
|
30 |
+
filtered = filtered[(filtered["27. BMI (Body Mass Index)"] >= bmi_range[0]) &
|
31 |
+
(filtered["27. BMI (Body Mass Index)"] <= bmi_range[1])]
|
32 |
+
|
33 |
+
# Line Chart: Weight/BMI/BFM over time
|
34 |
+
st.subheader("📈 Trends Over Time")
|
35 |
+
metric = st.selectbox("Select a Metric to Plot", ['6. Weight', '27. BMI (Body Mass Index)', '18. BFM (Body Fat Mass)'])
|
36 |
+
|
37 |
+
fig, ax = plt.subplots(figsize=(10, 5))
|
38 |
+
sns.lineplot(data=filtered, x="Test Date", y=metric, hue="ID", marker="o", ax=ax)
|
39 |
+
st.pyplot(fig)
|
40 |
+
|
41 |
+
# Cluster Scatterplot
|
42 |
+
st.subheader("🧬 Body Type Clusters")
|
43 |
+
fig2, ax2 = plt.subplots()
|
44 |
+
sns.scatterplot(data=filtered, x="18. BFM (Body Fat Mass)", y="24. SMM (Skeletal Muscle Mass)",
|
45 |
+
hue="Body Type Cluster", palette="Set1", ax=ax2)
|
46 |
+
st.pyplot(fig2)
|
47 |
+
|
48 |
+
# Summary Table
|
49 |
+
st.subheader("📋 Latest Measurements (Per Patient)")
|
50 |
+
latest = filtered.sort_values("Test Date").groupby("ID").tail(1)
|
51 |
+
st.dataframe(latest[["ID", "Test Date", "6. Weight", "27. BMI (Body Mass Index)",
|
52 |
+
"18. BFM (Body Fat Mass)", "24. SMM (Skeletal Muscle Mass)",
|
53 |
+
"58. BMR (Basal Metabolic Rate)", "Body Type Cluster"]])
|
54 |
+
|
55 |
+
# Download option
|
56 |
+
st.download_button("📥 Download Filtered Data", latest.to_csv(index=False), file_name="filtered_inbody.csv")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|