awacke1 commited on
Commit
b2049c8
·
1 Parent(s): 3fc7839

Create backup.app.py

Browse files
Files changed (1) hide show
  1. backup.app.py +73 -0
backup.app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Define a function to calculate assembly A
6
+ def calculate_assembly(ai_values, ni_values, N_T):
7
+ return sum([np.exp(ai) * ((ni - 1) / N_T) for ai, ni in zip(ai_values, ni_values)])
8
+
9
+ # Sample data for top ten geometric assemblies
10
+ example_assemblies = {
11
+ "Lighthouse": {"ai": 2.5, "ni": 1},
12
+ "Eyeglasses": {"ai": 1.8, "ni": 2},
13
+ "Stool": {"ai": 1.2, "ni": 3},
14
+ "Window": {"ai": 1.5, "ni": 4},
15
+ "Hand": {"ai": 2.0, "ni": 5},
16
+ "Dice": {"ai": 0.8, "ni": 6},
17
+ "Heaven": {"ai": 2.3, "ni": 7},
18
+ "Gate": {"ai": 1.7, "ni": 8},
19
+ "Cat": {"ai": 2.1, "ni": 9},
20
+ "Toes": {"ai": 1.0, "ni": 10},
21
+ }
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
+ Where:
30
+ - \( A \) is the assembly of the ensemble
31
+ - \( a_i \) is the assembly index of object \( i \)
32
+ - \( n_i \) is the copy number of object \( i \)
33
+ - \( N \) is the total number of unique objects
34
+ - \( N_T \) is the total number of objects in the ensemble
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
+ # Inputs for each object
43
+ ai_values = []
44
+ ni_values = []
45
+ objects = list(example_assemblies.keys())
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(objects, ai_values, color='skyblue')
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("Enter values and press 'Calculate Assembly' to see the result.")
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