Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,52 +22,55 @@ example_assemblies = {
|
|
22 |
|
23 |
# Streamlit App
|
24 |
st.title("The Assembly Equation Interactive Simulator")
|
25 |
-
st.write("""
|
26 |
-
The Assembly Equation is defined as:
|
27 |
-
\( A = \sum_{i=1}^{N} e^{a_i} \left(\frac{n_i - 1}{N_T}\right) \)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Sidebar for inputs
|
38 |
st.sidebar.header("Input Parameters")
|
39 |
-
N = st.sidebar.number_input("Enter the total number of unique objects (N):", min_value=1, value=len(example_assemblies))
|
40 |
N_T = st.sidebar.number_input("Enter the total number of objects in the ensemble (N_T):", min_value=1, value=50)
|
41 |
|
42 |
-
#
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
for i in range(N):
|
48 |
-
obj = objects[i]
|
49 |
-
ai = st.sidebar.number_input(f"Enter the assembly index of {obj} (a{i+1}):", value=example_assemblies[obj]["ai"], key=f"a{i+1}")
|
50 |
-
ni = st.sidebar.number_input(f"Enter the copy number of {obj} (n{i+1}):", min_value=0, value=example_assemblies[obj]["ni"], key=f"n{i+1}")
|
51 |
-
ai_values.append(ai)
|
52 |
-
ni_values.append(ni)
|
53 |
|
54 |
# Button to calculate assembly
|
55 |
if st.sidebar.button('Calculate Assembly'):
|
|
|
|
|
56 |
A = calculate_assembly(ai_values, ni_values, N_T)
|
57 |
st.write("The assembly of the ensemble (A) is:", A)
|
58 |
|
59 |
# Plotting the assembly index
|
60 |
fig, ax = plt.subplots()
|
61 |
-
ax.bar(
|
62 |
ax.set_xlabel('Objects')
|
63 |
ax.set_ylabel('Assembly Index')
|
64 |
ax.set_title('Assembly Index of Each Object')
|
65 |
st.pyplot(fig)
|
66 |
else:
|
67 |
-
st.write("
|
68 |
|
69 |
# Showing the dictionary of examples
|
70 |
st.write("Example inputs for simple assemblies:")
|
71 |
st.json(example_assemblies)
|
72 |
-
|
73 |
-
# Run the app with streamlit run <this_script_name>.py
|
|
|
22 |
|
23 |
# Streamlit App
|
24 |
st.title("The Assembly Equation Interactive Simulator")
|
|
|
|
|
|
|
25 |
|
26 |
+
# Display the Assembly Equation using LaTeX
|
27 |
+
st.latex(r'''
|
28 |
+
A = \sum_{i=1}^{N} e^{a_i} \left(\frac{n_i - 1}{N_T}\right)
|
29 |
+
''')
|
30 |
+
|
31 |
+
st.write("Where:")
|
32 |
+
st.latex(r'''
|
33 |
+
A \quad \text{is the assembly of the ensemble}
|
34 |
+
''')
|
35 |
+
st.latex(r'''
|
36 |
+
a_i \quad \text{is the assembly index of object } i
|
37 |
+
''')
|
38 |
+
st.latex(r'''
|
39 |
+
n_i \quad \text{is the copy number of object } i
|
40 |
+
''')
|
41 |
+
st.latex(r'''
|
42 |
+
N \quad \text{is the total number of unique objects}
|
43 |
+
''')
|
44 |
+
st.latex(r'''
|
45 |
+
N_T \quad \text{is the total number of objects in the ensemble}
|
46 |
+
''')
|
47 |
|
48 |
# Sidebar for inputs
|
49 |
st.sidebar.header("Input Parameters")
|
|
|
50 |
N_T = st.sidebar.number_input("Enter the total number of objects in the ensemble (N_T):", min_value=1, value=50)
|
51 |
|
52 |
+
# Display example assemblies
|
53 |
+
st.sidebar.write("Example Assemblies:")
|
54 |
+
for assembly, params in example_assemblies.items():
|
55 |
+
st.sidebar.write(f"{assembly}: ai = {params['ai']}, ni = {params['ni']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
# Button to calculate assembly
|
58 |
if st.sidebar.button('Calculate Assembly'):
|
59 |
+
ai_values = [params['ai'] for params in example_assemblies.values()]
|
60 |
+
ni_values = [params['ni'] for params in example_assemblies.values()]
|
61 |
A = calculate_assembly(ai_values, ni_values, N_T)
|
62 |
st.write("The assembly of the ensemble (A) is:", A)
|
63 |
|
64 |
# Plotting the assembly index
|
65 |
fig, ax = plt.subplots()
|
66 |
+
ax.bar(example_assemblies.keys(), ai_values, color='skyblue')
|
67 |
ax.set_xlabel('Objects')
|
68 |
ax.set_ylabel('Assembly Index')
|
69 |
ax.set_title('Assembly Index of Each Object')
|
70 |
st.pyplot(fig)
|
71 |
else:
|
72 |
+
st.write("Press 'Calculate Assembly' to see the result.")
|
73 |
|
74 |
# Showing the dictionary of examples
|
75 |
st.write("Example inputs for simple assemblies:")
|
76 |
st.json(example_assemblies)
|
|
|
|