Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import mahotas as mh
|
3 |
+
import pandas as pd
|
4 |
+
import plotly.express as px
|
5 |
+
|
6 |
+
# Define a list of medical conditions
|
7 |
+
conditions = [
|
8 |
+
{"name": "Depression", "test_for": "Patient Health Questionnaire-9 (PHQ-9)"},
|
9 |
+
{"name": "Anxiety", "test_for": "Generalized Anxiety Disorder-7 (GAD-7)"},
|
10 |
+
{"name": "Diabetes", "test_for": "Hemoglobin A1C test"},
|
11 |
+
{"name": "Hypertension", "test_for": "Blood pressure measurement"},
|
12 |
+
{"name": "Asthma", "test_for": "Pulmonary function test"},
|
13 |
+
{"name": "Cancer", "test_for": "Biopsy or imaging tests (e.g., CT scan, MRI)"},
|
14 |
+
{"name": "Arthritis", "test_for": "X-ray, MRI, or ultrasound"},
|
15 |
+
{"name": "Heart disease", "test_for": "Electrocardiogram (ECG)"},
|
16 |
+
{"name": "Obesity", "test_for": "Body mass index (BMI)"},
|
17 |
+
{"name": "Substance use disorder", "test_for": "Substance Abuse Subtle Screening Inventory (SASSI)"}
|
18 |
+
]
|
19 |
+
|
20 |
+
# Define a function to process images using Mahotas
|
21 |
+
def process_image(image):
|
22 |
+
# Convert the image to grayscale
|
23 |
+
grayscale_image = mh.colors.rgb2gray(image)
|
24 |
+
# Apply a Gaussian filter to the image to reduce noise
|
25 |
+
filtered_image = mh.gaussian_filter(grayscale_image, 4)
|
26 |
+
# Threshold the image to create a binary image
|
27 |
+
binary_image = filtered_image > mh.otsu(filtered_image)
|
28 |
+
# Compute the connected components in the binary image
|
29 |
+
labels, num_labels = mh.label(binary_image)
|
30 |
+
# Compute the size of each connected component
|
31 |
+
sizes = mh.labeled.labeled_size(labels)
|
32 |
+
# Sort the sizes in descending order
|
33 |
+
sorted_sizes = sorted(sizes, reverse=True)
|
34 |
+
# Return the top 10 sizes
|
35 |
+
return sorted_sizes[:10]
|
36 |
+
|
37 |
+
# Define the Streamlit app
|
38 |
+
def app():
|
39 |
+
# Add a title to the app
|
40 |
+
st.title("Mahotas Demo")
|
41 |
+
|
42 |
+
# Add a sidebar to the app
|
43 |
+
st.sidebar.title("Medical Conditions")
|
44 |
+
selected_condition = st.sidebar.selectbox("Select a condition", [c["name"] for c in conditions])
|
45 |
+
|
46 |
+
# Get the selected condition
|
47 |
+
condition = next(c for c in conditions if c["name"] == selected_condition)
|
48 |
+
|
49 |
+
# Display the selected condition
|
50 |
+
st.header(condition["name"])
|
51 |
+
st.write("Test for:", condition["test_for"])
|
52 |
+
|
53 |
+
# Load an example medical image
|
54 |
+
image = mh.imread("https://i.imgur.com/kPQoD8C.jpg")
|
55 |
+
|
56 |
+
# Process the image using Mahotas
|
57 |
+
sizes = process_image(image)
|
58 |
+
|
59 |
+
# Display the top 10 connected component sizes
|
60 |
+
df = pd.DataFrame({"Size": sizes})
|
61 |
+
st.write(df)
|
62 |
+
|
63 |
+
# Create a sunburst chart using Plotly
|
64 |
+
fig = px.sunburst(
|
65 |
+
df,
|
66 |
+
path=["Size"],
|
67 |
+
values="Size",
|
68 |
+
color="Size",
|
69 |
+
color_continuous_scale="blues"
|
70 |
+
)
|
71 |
+
st.plotly_chart(fig)
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
app()
|