manpreet88 commited on
Commit
98a5bf9
·
1 Parent(s): 320fafc

Update gradio_interface.py

Browse files
Files changed (1) hide show
  1. PolyAgent/gradio_interface.py +9 -18
PolyAgent/gradio_interface.py CHANGED
@@ -18,7 +18,7 @@ except Exception:
18
  import gradio as gr
19
 
20
  try:
21
- from orchestrator_updated import PolymerOrchestrator, OrchestratorConfig
22
  except Exception as e:
23
  raise ImportError(
24
  "Could not import PolymerOrchestrator from orchestrator_updated.py. "
@@ -77,7 +77,6 @@ DEFAULT_TARGET_BY_PROPERTY = {
77
  "glass transition": 60.0, # °C (example placeholder)
78
  "density": 1.20, # g/cm^3 (example placeholder)
79
  "melting": 150.0, # °C (example placeholder)
80
- "specific volume": 0.85, # cm^3/g (example placeholder)
81
  "thermal decomposition": 350.0, # °C (example placeholder)
82
  }
83
 
@@ -229,16 +228,12 @@ def _infer_property_from_questions(q: str) -> Optional[str]:
229
  return "density"
230
  if "melting" in cand or re.search(r"\btm\b", cand):
231
  return "melting"
232
- if "specific" in cand or re.search(r"\bsv\b", cand):
233
- return "specific volume"
234
  if "decomp" in cand or "decomposition" in cand or re.search(r"\btd\b", cand):
235
  return "thermal decomposition"
236
 
237
  # Token-based inference
238
  if "thermal decomposition" in s or "decomposition temperature" in s or "decomposition" in s or re.search(r"\btd\b", s):
239
  return "thermal decomposition"
240
- if "specific volume" in s or re.search(r"\bsv\b", s):
241
- return "specific volume"
242
  if "glass transition" in s or "glass-transition" in s or re.search(r"\btg\b", s):
243
  return "glass transition"
244
  if "melting" in s or "melt temperature" in s or re.search(r"\btm\b", s):
@@ -253,7 +248,7 @@ def _infer_target_value_from_questions(q: str, prop: Optional[str]) -> Optional[
253
  """
254
  Infer numeric target_value from free-text questions.
255
  - supports explicit: target_value=..., target: ..., tgt ...
256
- - supports property-attached: Tg 60, density 1.25, Td=380, sv 0.85, Tm 180
257
  """
258
  sl = (q or "").lower()
259
 
@@ -274,8 +269,6 @@ def _infer_target_value_from_questions(q: str, prop: Optional[str]) -> Optional[
274
  prop_patterns = [rf"\b(density|rho)\b\s*[:=]?\s*({_NUM_RE})"]
275
  elif prop == "melting":
276
  prop_patterns = [rf"\b(tm|melting)\b\s*[:=]?\s*({_NUM_RE})"]
277
- elif prop == "specific volume":
278
- prop_patterns = [rf"\b(specific\s*volume|sv)\b\s*[:=]?\s*({_NUM_RE})"]
279
  elif prop == "thermal decomposition":
280
  prop_patterns = [rf"\b(td|thermal\s*decomposition|decomposition)\b\s*[:=]?\s*({_NUM_RE})"]
281
 
@@ -295,8 +288,6 @@ def _infer_target_value_from_questions(q: str, prop: Optional[str]) -> Optional[
295
  tokens = ["density", "rho"]
296
  elif prop == "melting":
297
  tokens = ["tm", "melting"]
298
- elif prop == "specific volume":
299
- tokens = ["specific volume", "sv"]
300
  elif prop == "thermal decomposition":
301
  tokens = ["td", "thermal decomposition", "decomposition"]
302
 
@@ -1043,10 +1034,10 @@ def run_agent(state: Dict[str, Any], questions: str) -> Tuple[str, List[str]]:
1043
 
1044
  # Artifacts
1045
  imgs, extras = _maybe_add_artifacts(
1046
- orch,
1047
- report,
1048
- seed_psmiles_fallback=seed_psmiles,
1049
- property_name_fallback=property_name,
1050
  )
1051
  ctx.update(extras)
1052
 
@@ -1331,7 +1322,7 @@ def build_ui() -> gr.Blocks:
1331
  with gr.Accordion("Property Prediction", open=False):
1332
  prop = gr.Dropdown(
1333
  label="Property",
1334
- choices=["density", "glass transition", "melting", "specific volume", "thermal decomposition"],
1335
  value="glass transition",
1336
  )
1337
  psm_pred = gr.Textbox(label="Optional pSMILES (if not using previous extraction)")
@@ -1342,7 +1333,7 @@ def build_ui() -> gr.Blocks:
1342
  with gr.Accordion("Polymer Generation (inverse design)", open=False):
1343
  prop_g = gr.Dropdown(
1344
  label="Property (select generator)",
1345
- choices=["density", "glass transition", "melting", "specific volume", "thermal decomposition"],
1346
  value="glass transition",
1347
  )
1348
  tgt = gr.Number(label="target_value (required)", value=60.0, precision=4)
@@ -1374,7 +1365,7 @@ def build_ui() -> gr.Blocks:
1374
  psm_expl = gr.Textbox(label="pSMILES")
1375
  prop_expl = gr.Dropdown(
1376
  label="Property (for attribution)",
1377
- choices=["density", "glass transition", "melting", "specific volume", "thermal decomposition"],
1378
  value="glass transition",
1379
  )
1380
  btn_expl = gr.Button("Explain", variant="primary")
 
18
  import gradio as gr
19
 
20
  try:
21
+ from orchestrator import PolymerOrchestrator, OrchestratorConfig
22
  except Exception as e:
23
  raise ImportError(
24
  "Could not import PolymerOrchestrator from orchestrator_updated.py. "
 
77
  "glass transition": 60.0, # °C (example placeholder)
78
  "density": 1.20, # g/cm^3 (example placeholder)
79
  "melting": 150.0, # °C (example placeholder)
 
80
  "thermal decomposition": 350.0, # °C (example placeholder)
81
  }
82
 
 
228
  return "density"
229
  if "melting" in cand or re.search(r"\btm\b", cand):
230
  return "melting"
 
 
231
  if "decomp" in cand or "decomposition" in cand or re.search(r"\btd\b", cand):
232
  return "thermal decomposition"
233
 
234
  # Token-based inference
235
  if "thermal decomposition" in s or "decomposition temperature" in s or "decomposition" in s or re.search(r"\btd\b", s):
236
  return "thermal decomposition"
 
 
237
  if "glass transition" in s or "glass-transition" in s or re.search(r"\btg\b", s):
238
  return "glass transition"
239
  if "melting" in s or "melt temperature" in s or re.search(r"\btm\b", s):
 
248
  """
249
  Infer numeric target_value from free-text questions.
250
  - supports explicit: target_value=..., target: ..., tgt ...
251
+ - supports property-attached: Tg 60, density 1.25, Td=380, Tm 180
252
  """
253
  sl = (q or "").lower()
254
 
 
269
  prop_patterns = [rf"\b(density|rho)\b\s*[:=]?\s*({_NUM_RE})"]
270
  elif prop == "melting":
271
  prop_patterns = [rf"\b(tm|melting)\b\s*[:=]?\s*({_NUM_RE})"]
 
 
272
  elif prop == "thermal decomposition":
273
  prop_patterns = [rf"\b(td|thermal\s*decomposition|decomposition)\b\s*[:=]?\s*({_NUM_RE})"]
274
 
 
288
  tokens = ["density", "rho"]
289
  elif prop == "melting":
290
  tokens = ["tm", "melting"]
 
 
291
  elif prop == "thermal decomposition":
292
  tokens = ["td", "thermal decomposition", "decomposition"]
293
 
 
1034
 
1035
  # Artifacts
1036
  imgs, extras = _maybe_add_artifacts(
1037
+ orch,
1038
+ report,
1039
+ seed_psmiles_fallback=seed_psmiles,
1040
+ property_name_fallback=property_name,
1041
  )
1042
  ctx.update(extras)
1043
 
 
1322
  with gr.Accordion("Property Prediction", open=False):
1323
  prop = gr.Dropdown(
1324
  label="Property",
1325
+ choices=["density", "glass transition", "melting", "thermal decomposition"],
1326
  value="glass transition",
1327
  )
1328
  psm_pred = gr.Textbox(label="Optional pSMILES (if not using previous extraction)")
 
1333
  with gr.Accordion("Polymer Generation (inverse design)", open=False):
1334
  prop_g = gr.Dropdown(
1335
  label="Property (select generator)",
1336
+ choices=["density", "glass transition", "melting", "thermal decomposition"],
1337
  value="glass transition",
1338
  )
1339
  tgt = gr.Number(label="target_value (required)", value=60.0, precision=4)
 
1365
  psm_expl = gr.Textbox(label="pSMILES")
1366
  prop_expl = gr.Dropdown(
1367
  label="Property (for attribution)",
1368
+ choices=["density", "glass transition", "melting", "thermal decomposition"],
1369
  value="glass transition",
1370
  )
1371
  btn_expl = gr.Button("Explain", variant="primary")