Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -272,35 +272,69 @@ def update_radar_plot(smiles, df_results):
|
|
| 272 |
# Extract the row for the selected SMILES
|
| 273 |
row = df_results[df_results["p-SMILES"] == smiles].iloc[0]
|
| 274 |
|
| 275 |
-
# Helper to pull
|
| 276 |
def extract_val(x): return float(str(x).split(' ')[1])
|
| 277 |
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
values = [
|
| 281 |
min(extract_val(row['Strength (GPa)']) / 0.15, 1.0),
|
| 282 |
min(extract_val(row['Tg (°C)']) / 300, 1.0),
|
| 283 |
min(extract_val(row['Degradability']), 1.0),
|
| 284 |
-
min(1.0 - (extract_val(row['SA Score']) / 10), 1.0)
|
| 285 |
]
|
| 286 |
|
| 287 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
plot_metrics = metrics + [metrics[0]]
|
| 289 |
plot_values = values + [values[0]]
|
|
|
|
| 290 |
|
| 291 |
fig = go.Figure()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
fig.add_trace(go.Scatterpolar(
|
| 293 |
r=plot_values,
|
| 294 |
theta=plot_metrics,
|
| 295 |
fill='toself',
|
| 296 |
-
|
| 297 |
-
line=dict(color=
|
|
|
|
| 298 |
))
|
| 299 |
|
| 300 |
fig.update_layout(
|
| 301 |
-
polar=dict(
|
| 302 |
-
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
)
|
| 305 |
return fig
|
| 306 |
|
|
@@ -376,15 +410,24 @@ with gr.Blocks(title="PolymerDesignAI") as demo:
|
|
| 376 |
|
| 377 |
gr.Markdown("### 🕵️ Candidate Deep-Dive")
|
| 378 |
with gr.Row():
|
| 379 |
-
with gr.Column(scale=
|
| 380 |
selection_dropdown = gr.Dropdown(label="Select a SMILES to inspect", choices=[])
|
| 381 |
radar_plot = gr.Plot(label="Radar Profile")
|
| 382 |
-
with gr.Column(scale=
|
| 383 |
-
gr.Markdown("""
|
| 384 |
-
*
|
| 385 |
-
* **
|
| 386 |
-
* **
|
| 387 |
-
* **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
csv_out = gr.File(label="Download Full Results")
|
| 390 |
|
|
|
|
| 272 |
# Extract the row for the selected SMILES
|
| 273 |
row = df_results[df_results["p-SMILES"] == smiles].iloc[0]
|
| 274 |
|
| 275 |
+
# Helper to pull numeric value
|
| 276 |
def extract_val(x): return float(str(x).split(' ')[1])
|
| 277 |
|
| 278 |
+
# Classification-based coloring
|
| 279 |
+
status = row['Classification']
|
| 280 |
+
color = "#2ecc71" if "Excellent" in status else "#f1c40f" if "Review" in status else "#e74c3c"
|
| 281 |
+
|
| 282 |
+
# Define standardized labels with units
|
| 283 |
+
metrics = ['Strength (0.15 GPa)', 'Tg (300°C)', 'Degradability (1.0)', 'Synthesizability (SA 1.0)']
|
| 284 |
+
|
| 285 |
+
# Normalize values for candidate (0 to 1 scale)
|
| 286 |
values = [
|
| 287 |
min(extract_val(row['Strength (GPa)']) / 0.15, 1.0),
|
| 288 |
min(extract_val(row['Tg (°C)']) / 300, 1.0),
|
| 289 |
min(extract_val(row['Degradability']), 1.0),
|
| 290 |
+
min(1.0 - (extract_val(row['SA Score']) / 10), 1.0)
|
| 291 |
]
|
| 292 |
|
| 293 |
+
# Define generic "Target Area" (Industry Standard Benchmark)
|
| 294 |
+
# We set this at 0.6 as a visual reference for "Pass"
|
| 295 |
+
target_values = [0.6, 0.6, 0.6, 0.6]
|
| 296 |
+
|
| 297 |
+
# Close loops
|
| 298 |
plot_metrics = metrics + [metrics[0]]
|
| 299 |
plot_values = values + [values[0]]
|
| 300 |
+
plot_target = target_values + [target_values[0]]
|
| 301 |
|
| 302 |
fig = go.Figure()
|
| 303 |
+
|
| 304 |
+
# 1. Add Target Area (The grey background reference)
|
| 305 |
+
fig.add_trace(go.Scatterpolar(
|
| 306 |
+
r=plot_target,
|
| 307 |
+
theta=plot_metrics,
|
| 308 |
+
fill='toself',
|
| 309 |
+
fillcolor='rgba(128, 128, 128, 0.2)',
|
| 310 |
+
line=dict(color='rgba(128, 128, 128, 0.5)', dash='dash'),
|
| 311 |
+
name='Industry Benchmark'
|
| 312 |
+
))
|
| 313 |
+
|
| 314 |
+
# 2. Add Candidate Trace (Color-coded)
|
| 315 |
fig.add_trace(go.Scatterpolar(
|
| 316 |
r=plot_values,
|
| 317 |
theta=plot_metrics,
|
| 318 |
fill='toself',
|
| 319 |
+
fillcolor=f'rgba{tuple(int(color.lstrip("#")[i:i+2], 16) for i in (0, 2, 4)) + (0.5,)}',
|
| 320 |
+
line=dict(color=color, width=3),
|
| 321 |
+
name='Candidate Performance'
|
| 322 |
))
|
| 323 |
|
| 324 |
fig.update_layout(
|
| 325 |
+
polar=dict(
|
| 326 |
+
radialaxis=dict(
|
| 327 |
+
visible=True,
|
| 328 |
+
range=[0, 1],
|
| 329 |
+
tickvals=[0.25, 0.5, 0.75, 1.0],
|
| 330 |
+
gridcolor="lightgrey"
|
| 331 |
+
),
|
| 332 |
+
angularaxis=dict(gridcolor="lightgrey")
|
| 333 |
+
),
|
| 334 |
+
showlegend=True,
|
| 335 |
+
legend=dict(orientation="h", yanchor="bottom", y=-0.2, xanchor="center", x=0.5),
|
| 336 |
+
margin=dict(l=40, r=40, t=40, b=40), # Fixes the empty space issue
|
| 337 |
+
title=dict(text=f"Performance Fingerprint", x=0.5)
|
| 338 |
)
|
| 339 |
return fig
|
| 340 |
|
|
|
|
| 410 |
|
| 411 |
gr.Markdown("### 🕵️ Candidate Deep-Dive")
|
| 412 |
with gr.Row():
|
| 413 |
+
with gr.Column(scale=3): # Increased scale to fix empty space
|
| 414 |
selection_dropdown = gr.Dropdown(label="Select a SMILES to inspect", choices=[])
|
| 415 |
radar_plot = gr.Plot(label="Radar Profile")
|
| 416 |
+
with gr.Column(scale=2):
|
| 417 |
+
gr.Markdown("""
|
| 418 |
+
**📊 How to Read the Radar Plot:**
|
| 419 |
+
* **Colored Area**: The specific performance of your selected polymer.
|
| 420 |
+
* **Dashed Grey Area**: The **Industry Benchmark**. If the colored area covers the grey area, it meets standard requirements.
|
| 421 |
+
* **Color Coding**: Matches the classification (Green = Excellent, Yellow = Review, Red = Bad).
|
| 422 |
+
|
| 423 |
+
**⚖️ Benchmark Scales:**
|
| 424 |
+
* **Strength**: Normalized against **0.15 GPa**.
|
| 425 |
+
* **Tg**: Normalized against **300°C**.
|
| 426 |
+
* **Degradability**: Measured on a **0 to 1** scale.
|
| 427 |
+
* **Synthesizability**: Higher is better. It represents the inverse of the SA Score (lower complexity).
|
| 428 |
+
|
| 429 |
+
**🎯 Grid Lines:** Circles represent **25%, 50%, 75%, and 100%** of the target performance.
|
| 430 |
+
""")
|
| 431 |
|
| 432 |
csv_out = gr.File(label="Download Full Results")
|
| 433 |
|