gangli71 commited on
Commit
9d57353
·
verified ·
1 Parent(s): 64df339

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +288 -0
  2. requirements.txt +6 -2
app.py ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #######################
2
+ # Import libraries
3
+ import streamlit as st
4
+ import pandas as pd
5
+ import altair as alt
6
+ import plotly.express as px
7
+ from PIL import Image # Used to open and handle image files
8
+ import matplotlib
9
+ import matplotlib.pyplot as plt
10
+ import numpy as np
11
+
12
+
13
+ #######################
14
+ # Page configuration
15
+ st.set_page_config(
16
+ page_title="Inverse Design of Thermoplastic Composites for Thermoforming",
17
+ # page_icon="🏂",
18
+ layout="wide",
19
+ initial_sidebar_state="collapsed")
20
+
21
+ alt.themes.enable('default')
22
+
23
+ #######################
24
+ # CSS styling
25
+
26
+ st.markdown("""
27
+ <style>
28
+ /* Target the input element within its container (adjust class name as needed via browser inspection) */
29
+ .stTextInput input {
30
+ border: 1px solid #333333; /* Set border width, style, and color */
31
+ border-radius: 6px; /* Optional: adds rounded corners */
32
+ padding: 10px; /* Optional: adds inner spacing */
33
+ }
34
+ </style>
35
+ """, unsafe_allow_html=True)
36
+
37
+ st.markdown("""
38
+ <style>
39
+
40
+ [data-testid="block-container"] {
41
+ padding-left: 2rem;
42
+ padding-right: 2rem;
43
+ padding-top: 1rem;
44
+ padding-bottom: 0rem;
45
+ margin-bottom: -7rem;
46
+ }
47
+
48
+ [data-testid="stVerticalBlock"] {
49
+ padding-left: 0rem;
50
+ padding-right: 0rem;
51
+ }
52
+
53
+ [data-testid="stMetric"] {
54
+ background-color: #393939;
55
+ text-align: center;
56
+ padding: 15px 0;
57
+ }
58
+
59
+ [data-testid="stMetricLabel"] {
60
+ display: flex;
61
+ justify-content: center;
62
+ align-items: center;
63
+ }
64
+
65
+ [data-testid="stMetricDeltaIcon-Up"] {
66
+ position: relative;
67
+ left: 38%;
68
+ -webkit-transform: translateX(-50%);
69
+ -ms-transform: translateX(-50%);
70
+ transform: translateX(-50%);
71
+ }
72
+
73
+ [data-testid="stMetricDeltaIcon-Down"] {
74
+ position: relative;
75
+ left: 38%;
76
+ -webkit-transform: translateX(-50%);
77
+ -ms-transform: translateX(-50%);
78
+ transform: translateX(-50%);
79
+ }
80
+
81
+ /* Main app + sidebar, target the label element itself */
82
+ [data-testid="stAppViewContainer"] label,
83
+ [data-testid="stWidgetLabel"] label {
84
+ font-size: 18px !important;
85
+ font-weight: 600 !important; /* optional */
86
+ color: #444 !important; /* optional */
87
+ }
88
+
89
+ /* Some versions wrap label text inside a <div><p> */
90
+ [data-testid="stAppViewContainer"] label > div > p,
91
+ [data-testid="stWidgetLabel"] label > div > p {
92
+ font-size: 18px !important;
93
+ font-weight: 600 !important;
94
+ }
95
+ </style>
96
+ """, unsafe_allow_html=True)
97
+
98
+ st.markdown("""
99
+ <style>
100
+ div.stButton > button:first-child {
101
+ background-color: #ee7700; /* background */
102
+ color: white; /* White text */
103
+ font-size: 20px;
104
+ border-radius: 10px;
105
+ # display: block; # this line and the next center the button horizontally
106
+ # margin: 0 auto;
107
+ }
108
+ </style>
109
+ """, unsafe_allow_html=True)
110
+
111
+ st.markdown("""
112
+ <style>
113
+ div[data-testid="stVirtualDropdown"] > div {
114
+ max-height: 10px !important; /* Adjust this value as needed */
115
+ overflow-y: auto;
116
+ }
117
+ </style>
118
+ """, unsafe_allow_html=True)
119
+
120
+
121
+ st.set_page_config(initial_sidebar_state="collapsed")
122
+
123
+ st.markdown(
124
+ """
125
+ <style>
126
+ [data-testid="collapsedControl"] {
127
+ display: none
128
+ }
129
+ </style>
130
+ """,
131
+ unsafe_allow_html=True,
132
+ )
133
+
134
+
135
+ st.markdown("""
136
+ <style>
137
+ /* Target all table cells and headers */
138
+ table, th, td {
139
+ border: 2px solid #333333; /* Change to your desired color */
140
+ border-collapse: collapse; /* Ensure borders touch */
141
+ }
142
+ /* Optional: adjust padding */
143
+ th, td {
144
+ padding: 8px;
145
+ }
146
+ </style>
147
+ """, unsafe_allow_html=True)
148
+
149
+ st.markdown("""
150
+ <style>
151
+ /* Targets the table headers */
152
+ .stDataFrame table th {
153
+ font-size: 26px;
154
+ }
155
+ /* Targets the table data cells */
156
+ .stDataFrame table td {
157
+ font-size: 24px;
158
+ }
159
+ </style>
160
+ """, unsafe_allow_html=True)
161
+
162
+
163
+
164
+ #######################
165
+ font = {'size' : 18}
166
+
167
+ matplotlib.rc('font', **font)
168
+
169
+ #######################
170
+ if 'input_changed' not in st.session_state:
171
+ st.session_state.input_changed= False
172
+ def input_typed_in():
173
+ st.session_state.input_changed= True
174
+
175
+ if 'AM_input_changed' not in st.session_state:
176
+ st.session_state.AM_input_changed= False
177
+ def AM_typed_in():
178
+ st.session_state.AM_input_changed= True
179
+
180
+
181
+
182
+ if 'AM_input_button_clicked' not in st.session_state:
183
+ st.session_state.AM_input_button_clicked= False
184
+ def AM_input_click():
185
+ st.session_state.AM_input_button_clicked = True
186
+
187
+ if 'AM_design_button_clicked' not in st.session_state:
188
+ st.session_state.AM_design_button_clicked= False
189
+ def AM_design_click():
190
+ st.session_state.AM_design_button_clicked = True
191
+
192
+
193
+ def style_dataframe_borders(df):
194
+ return df.style.set_table_styles([
195
+ {'selector': 'td, th', 'props': [('border', '2px solid #000000')]} # Green border
196
+ ])
197
+ #######################
198
+ # Load data
199
+ #df_reshaped = pd.read_csv('data/us-population-2010-2019-reshaped.csv')
200
+
201
+ ######## Initialize data #############
202
+ nlayers=4
203
+ vf=0.5
204
+ angle=30
205
+
206
+ #######################
207
+ # Main Panel
208
+
209
+ data_materials={
210
+ 'Matrix':['ABS','Polyurethane','Nylon 6','Nylon 6','Nylon 66','PE','PP'],
211
+ 'Filler':['Carbon Black','Glass Fiber','Glass Fiber','Carbon Fiber','Glass Fiber','Carbon Fiber','Glass Fiber'],
212
+ 'VF':['15%','20%','20%','40%','30%','20%','30%'],
213
+ 'Feature':['Blend','Extruded','Molded','Molded','Molded','Molded','Molded']
214
+ }
215
+
216
+ data_physical = {
217
+ 'Forming T (C)': ['180', '185', '190'],
218
+ 'Punch V (m/s)': ['1.05', '1.8','1.67'],
219
+ 'Cooling time (s)': ['45','80','120'],
220
+ 'Holding force (kN)': ['23','24','25']
221
+ }
222
+
223
+ st.title("Inverse Design of Thermoplastic Composites for Additive Manufacturing")
224
+ st.write("")
225
+ st.write("")
226
+ st.write("")
227
+
228
+ st.write("")
229
+ st.write(r"$\textsf{\textbf{\Large Additive Manufacturing Requirements}}$")
230
+
231
+ col1_row1, col2_row1, col3_row1, col4_row1 = st.columns([0.25,0.25,0.25,0.25])
232
+ with col1_row1:
233
+ with st.container(border=False): # Container with a border
234
+ angleA= st.number_input("Maximum warpage angle A (degree):", format="%.2f", width=300, value=1.0, key="A", on_change=AM_typed_in)
235
+ angleB= st.number_input("Maximum warpage angle B (degree):", format="%.2f", width=300, value=1.0, key="B", on_change=AM_typed_in)
236
+
237
+ with col2_row1:
238
+ with st.container(border=False): # Container with a border
239
+ angleC= st.number_input("Maximum warpage angle C (degree):", format="%.2f", width=300, value=1.0, key="C", on_change=AM_typed_in)
240
+ max_stress= st.number_input("Maximum residual stress (MPa):", format="%.2f", width=300, value=100.0, key="max_stress", on_change=AM_typed_in)
241
+
242
+ with col3_row1:
243
+ with st.container(border=False): # Container with a border
244
+ image = Image.open('figures/Hat_Section_AM1.png')
245
+ new_image = image.resize((350, 200))
246
+ st.image(new_image, caption='')
247
+
248
+ with col4_row1:
249
+ with st.container(border=False): # Container with a border
250
+ image = Image.open('figures/Hat_Section_AM2.png')
251
+ new_image = image.resize((350, 200))
252
+ st.image(new_image, caption='')
253
+
254
+
255
+ st.write("")
256
+ if st.session_state.AM_input_changed == True:
257
+ st.session_state.AM_design_button_clicked = False
258
+ st.session_state.AM_input_changed = False
259
+
260
+ st.button("AM process design", width=400, on_click=AM_design_click)
261
+ if st.session_state.AM_design_button_clicked == True:
262
+ st.write("Process parameters")
263
+ data1 = pd.DataFrame({
264
+ 'Matrix material': ['PP'],
265
+ 'Fiber material': ['Glass'],
266
+ 'Build direction': ['Vertical']})
267
+ #st.table(data1)
268
+ # Define styles
269
+ styles = [
270
+ dict(selector="th", props=[('font-size', '14px')]), # Header font size
271
+ dict(selector="td", props=[('font-size', '12px')]) # Cell font size
272
+ ]
273
+ styled_df = style_dataframe_borders(data1)
274
+
275
+ st.dataframe(data1, hide_index=True, width=500)
276
+
277
+ data2 = pd.DataFrame({
278
+ 'Nozzel velocity (cm/s)': [100],
279
+ 'Extruder temperature (C)': [240],
280
+ 'Bed temperature (C)': [110]})
281
+ st.dataframe(data2, hide_index=True, width=500)
282
+
283
+
284
+
285
+
286
+
287
+
288
+
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
  pandas
3
- streamlit
 
 
 
 
 
1
+ streamlit
2
  pandas
3
+ altair
4
+ plotly
5
+ PIL
6
+ pathlib
7
+ numpy