Spaces:
Runtime error
Runtime error
Create backup-app.py
Browse files- backup-app.py +65 -0
backup-app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
# Define function to read CSV file
|
5 |
+
def read_data():
|
6 |
+
data = pd.read_csv("health_conditions.csv")
|
7 |
+
return data
|
8 |
+
|
9 |
+
# Define function to update CSV file
|
10 |
+
def update_data(data):
|
11 |
+
data.to_csv("health_conditions.csv", index=False)
|
12 |
+
|
13 |
+
# Define function to display data
|
14 |
+
def display_data(data):
|
15 |
+
st.write(data)
|
16 |
+
|
17 |
+
# Define function to add new data
|
18 |
+
def add_data(data, new_data):
|
19 |
+
data = pd.concat([data, new_data], ignore_index=True)
|
20 |
+
return data
|
21 |
+
|
22 |
+
# Define function to delete data
|
23 |
+
def delete_data(data, indices):
|
24 |
+
data = data.drop(indices, axis=0)
|
25 |
+
data = data.reset_index(drop=True)
|
26 |
+
return data
|
27 |
+
|
28 |
+
# Define function to download data as CSV file
|
29 |
+
def download_data(data):
|
30 |
+
csv = data.to_csv(index=False)
|
31 |
+
href = f'<a href="data:file/csv;base64,{base64.b64encode(csv.encode()).decode()}" download="health_conditions.csv">Download CSV file</a>'
|
32 |
+
return href
|
33 |
+
|
34 |
+
# Define main function
|
35 |
+
def main():
|
36 |
+
st.title("Health Condition Costs Visualization")
|
37 |
+
data = read_data()
|
38 |
+
display_data(data)
|
39 |
+
st.write("To add new data, please fill in the form below:")
|
40 |
+
condition = st.text_input("Condition")
|
41 |
+
icd10_code = st.text_input("ICD10 Code")
|
42 |
+
snomed_code = st.text_input("SNOMED Code")
|
43 |
+
loinc_code = st.text_input("LOINC Code")
|
44 |
+
assessment = st.text_input("Assessment")
|
45 |
+
if st.button("Add"):
|
46 |
+
new_data = pd.DataFrame({
|
47 |
+
"condition": [condition],
|
48 |
+
"ICD10_code": [icd10_code],
|
49 |
+
"SNOMED_code": [snomed_code],
|
50 |
+
"LOINC_code": [loinc_code],
|
51 |
+
"assessment": [assessment]
|
52 |
+
})
|
53 |
+
data = add_data(data, new_data)
|
54 |
+
update_data(data)
|
55 |
+
indices = []
|
56 |
+
for i, row in data.iterrows():
|
57 |
+
if st.checkbox(f"Delete row {i+1}"):
|
58 |
+
indices.append(i)
|
59 |
+
if len(indices) > 0:
|
60 |
+
data = delete_data(data, indices)
|
61 |
+
update_data(data)
|
62 |
+
st.markdown(download_data(data), unsafe_allow_html=True)
|
63 |
+
|
64 |
+
if __name__ == "__main__":
|
65 |
+
main()
|