Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -138,7 +138,7 @@ def batch_predict(app_choice, file_obj):
|
|
| 138 |
|
| 139 |
# --- 5. AUTONOMOUS DESIGN LOGIC ---
|
| 140 |
|
| 141 |
-
def generate_and_screen(num_to_gen, app_mode):
|
| 142 |
candidates = []
|
| 143 |
generated_fps = []
|
| 144 |
max_attempts = num_to_gen * 15
|
|
@@ -196,9 +196,9 @@ def generate_and_screen(num_to_gen, app_mode):
|
|
| 196 |
"_s": s, "_t": t
|
| 197 |
})
|
| 198 |
|
| 199 |
-
df = pd.DataFrame(candidates)
|
| 200 |
|
| 201 |
-
#
|
| 202 |
df_sorted = df.sort_values(by="_s")
|
| 203 |
px_pts, py_pts, cur_max = [], [], -1000
|
| 204 |
pareto_indices = []
|
|
@@ -207,15 +207,19 @@ def generate_and_screen(num_to_gen, app_mode):
|
|
| 207 |
px_pts.append(row["_s"]); py_pts.append(row["_t"]); cur_max = row["_t"]
|
| 208 |
pareto_indices.append(i)
|
| 209 |
|
| 210 |
-
#
|
| 211 |
if toggle_view == "Multi-objective Pareto optimal":
|
| 212 |
df = df.loc[pareto_indices]
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
| 216 |
fig.add_trace(go.Scatter(x=px_pts, y=py_pts, mode='lines', name='Pareto Frontier', line=dict(color='black', dash='dash')))
|
| 217 |
|
|
|
|
| 218 |
df = df.sort_values(by="_s", ascending=False)
|
|
|
|
| 219 |
output_path = tempfile.NamedTemporaryFile(delete=False, suffix=".csv").name
|
| 220 |
df.to_csv(output_path, index=False)
|
| 221 |
return df.drop(columns=["_s", "_t"]), output_path, fig
|
|
@@ -223,13 +227,19 @@ def generate_and_screen(num_to_gen, app_mode):
|
|
| 223 |
def calculate_weighted_rank(df, app_mode):
|
| 224 |
if df is None or df.empty: return None, None
|
| 225 |
def clean(x): return float(str(x).split(' ')[1])
|
| 226 |
-
s_n, t_n, d_n = (df['Strength (GPa)'].apply(clean)-0.01)/0.14, (df['Tg (°C)'].apply(clean)-50)/250, df['Degradability'].apply(clean)
|
| 227 |
-
sa_p = np.exp(-0.4 * (df['SA Score'].apply(clean) - 1))
|
| 228 |
|
| 229 |
-
#
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
df = df.sort_values(by="Rank Score", ascending=False)
|
| 235 |
output_path = tempfile.NamedTemporaryFile(delete=False, suffix=".csv").name
|
|
|
|
| 138 |
|
| 139 |
# --- 5. AUTONOMOUS DESIGN LOGIC ---
|
| 140 |
|
| 141 |
+
def generate_and_screen(num_to_gen, app_mode, toggle_view):
|
| 142 |
candidates = []
|
| 143 |
generated_fps = []
|
| 144 |
max_attempts = num_to_gen * 15
|
|
|
|
| 196 |
"_s": s, "_t": t
|
| 197 |
})
|
| 198 |
|
| 199 |
+
df = pd.DataFrame(candidates)
|
| 200 |
|
| 201 |
+
# PARETO CALCULATION
|
| 202 |
df_sorted = df.sort_values(by="_s")
|
| 203 |
px_pts, py_pts, cur_max = [], [], -1000
|
| 204 |
pareto_indices = []
|
|
|
|
| 207 |
px_pts.append(row["_s"]); py_pts.append(row["_t"]); cur_max = row["_t"]
|
| 208 |
pareto_indices.append(i)
|
| 209 |
|
| 210 |
+
# APPLY THE TOGGLE logic (Point 1 from Professor)
|
| 211 |
if toggle_view == "Multi-objective Pareto optimal":
|
| 212 |
df = df.loc[pareto_indices]
|
| 213 |
|
| 214 |
+
# Create the Plot
|
| 215 |
+
fig = px.scatter(df_sorted, x="_s", y="_t", color="Classification",
|
| 216 |
+
color_discrete_map={"Excellent": "#2ecc71", "Review": "#f1c40f", "Bad": "#e74c3c"},
|
| 217 |
+
title=f"Pareto Analysis: {app_mode}", labels={"_s": "Strength (GPa)", "_t": "Tg (°C)"})
|
| 218 |
fig.add_trace(go.Scatter(x=px_pts, y=py_pts, mode='lines', name='Pareto Frontier', line=dict(color='black', dash='dash')))
|
| 219 |
|
| 220 |
+
# Final sort for the table
|
| 221 |
df = df.sort_values(by="_s", ascending=False)
|
| 222 |
+
|
| 223 |
output_path = tempfile.NamedTemporaryFile(delete=False, suffix=".csv").name
|
| 224 |
df.to_csv(output_path, index=False)
|
| 225 |
return df.drop(columns=["_s", "_t"]), output_path, fig
|
|
|
|
| 227 |
def calculate_weighted_rank(df, app_mode):
|
| 228 |
if df is None or df.empty: return None, None
|
| 229 |
def clean(x): return float(str(x).split(' ')[1])
|
|
|
|
|
|
|
| 230 |
|
| 231 |
+
# Standardize normalization for all properties
|
| 232 |
+
s_norm = (df['Strength (GPa)'].apply(clean) - 0.01) / 0.14
|
| 233 |
+
t_norm = (df['Tg (°C)'].apply(clean) - 50) / 250
|
| 234 |
+
d_norm = df['Degradability'].apply(clean) # Degradability is usually 0-1, so no norm needed
|
| 235 |
+
sa_penalty = np.exp(-0.4 * (df['SA Score'].apply(clean) - 1))
|
| 236 |
+
|
| 237 |
+
if app_mode == "Aerospace Mode":
|
| 238 |
+
df['Rank Score'] = (s_norm * 0.5 + t_norm * 0.3 + sa_penalty * 0.2).round(4)
|
| 239 |
+
elif app_mode == "Battery Mode":
|
| 240 |
+
df['Rank Score'] = (t_norm * 0.5 + s_norm * 0.2 + sa_penalty * 0.3).round(4)
|
| 241 |
+
else: # Biomedical Mode
|
| 242 |
+
df['Rank Score'] = (d_norm * 0.6 + s_norm * 0.1 + sa_penalty * 0.3).round(4)
|
| 243 |
|
| 244 |
df = df.sort_values(by="Rank Score", ascending=False)
|
| 245 |
output_path = tempfile.NamedTemporaryFile(delete=False, suffix=".csv").name
|