vimalk78 commited on
Commit
d4decd1
·
verified ·
1 Parent(s): 90ad1ff

ui: drop top_k slider — it was a no-op given threshold + kind-conditioning

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -165,7 +165,7 @@ def _detect_kind(yaml_text: str) -> str:
165
  return m.group(1) if m else "?"
166
 
167
 
168
- def _suggest_one(yaml_text: str, threshold: float, top_k: int) -> str:
169
  n_lines = len(yaml_text.splitlines())
170
  if n_lines > MAX_LINES_PER_DOC:
171
  return (
@@ -179,7 +179,7 @@ def _suggest_one(yaml_text: str, threshold: float, top_k: int) -> str:
179
  try:
180
  suggestions, _skipped = suggest_missing_fields(
181
  MODEL, VOCAB, yaml_text,
182
- threshold=threshold, top_k=top_k,
183
  )
184
  except Exception as e:
185
  return f"**Parse error:**\n```\n{e}\n```"
@@ -191,7 +191,7 @@ def _suggest_one(yaml_text: str, threshold: float, top_k: int) -> str:
191
  return _format_suggestions(suggestions)
192
 
193
 
194
- def suggest(yaml_text: str, threshold: float, top_k: int) -> str:
195
  yaml_text = (yaml_text or "").strip()
196
  if not yaml_text:
197
  return "_Paste a YAML manifest above to see missing-field suggestions._"
@@ -202,14 +202,14 @@ def suggest(yaml_text: str, threshold: float, top_k: int) -> str:
202
 
203
  # Single doc: skip the document header for cleaner output
204
  if len(docs) == 1:
205
- return _suggest_one(docs[0], threshold, top_k)
206
 
207
  # Multi-doc: prefix each doc's output with a kind/index header
208
  blocks: list[str] = []
209
  for i, doc_text in enumerate(docs, 1):
210
  kind = _detect_kind(doc_text)
211
  header = f"### Document {i}: `{kind}`"
212
- blocks.append(header + "\n\n" + _suggest_one(doc_text, threshold, top_k))
213
  return "\n\n---\n\n".join(blocks)
214
 
215
 
@@ -503,21 +503,16 @@ Code: [github.com/vimalk78/yaml-bert](https://github.com/vimalk78/yaml-bert) ·
503
  label="YAML input",
504
  value=EXAMPLE_NGINX,
505
  )
506
- with gr.Row():
507
- threshold = gr.Slider(
508
- minimum=0.05, maximum=0.95, value=0.1, step=0.05,
509
- label="Confidence threshold",
510
- )
511
- top_k = gr.Slider(
512
- minimum=3, maximum=20, value=10, step=1,
513
- label="Top-K predictions per position",
514
- )
515
  submit = gr.Button("Suggest missing fields", variant="primary")
516
 
517
  with gr.Column(scale=1):
518
  output = gr.Markdown(label="Suggestions", value="")
519
 
520
- submit.click(fn=suggest, inputs=[yaml_input, threshold, top_k], outputs=output)
521
  # No auto-trigger on yaml_input.change — typing/pasting a long YAML would
522
  # fire many inference requests and back up the queue. Button click only.
523
 
 
165
  return m.group(1) if m else "?"
166
 
167
 
168
+ def _suggest_one(yaml_text: str, threshold: float) -> str:
169
  n_lines = len(yaml_text.splitlines())
170
  if n_lines > MAX_LINES_PER_DOC:
171
  return (
 
179
  try:
180
  suggestions, _skipped = suggest_missing_fields(
181
  MODEL, VOCAB, yaml_text,
182
+ threshold=threshold,
183
  )
184
  except Exception as e:
185
  return f"**Parse error:**\n```\n{e}\n```"
 
191
  return _format_suggestions(suggestions)
192
 
193
 
194
+ def suggest(yaml_text: str, threshold: float) -> str:
195
  yaml_text = (yaml_text or "").strip()
196
  if not yaml_text:
197
  return "_Paste a YAML manifest above to see missing-field suggestions._"
 
202
 
203
  # Single doc: skip the document header for cleaner output
204
  if len(docs) == 1:
205
+ return _suggest_one(docs[0], threshold)
206
 
207
  # Multi-doc: prefix each doc's output with a kind/index header
208
  blocks: list[str] = []
209
  for i, doc_text in enumerate(docs, 1):
210
  kind = _detect_kind(doc_text)
211
  header = f"### Document {i}: `{kind}`"
212
+ blocks.append(header + "\n\n" + _suggest_one(doc_text, threshold))
213
  return "\n\n---\n\n".join(blocks)
214
 
215
 
 
503
  label="YAML input",
504
  value=EXAMPLE_NGINX,
505
  )
506
+ threshold = gr.Slider(
507
+ minimum=0.05, maximum=0.95, value=0.1, step=0.05,
508
+ label="Confidence threshold",
509
+ )
 
 
 
 
 
510
  submit = gr.Button("Suggest missing fields", variant="primary")
511
 
512
  with gr.Column(scale=1):
513
  output = gr.Markdown(label="Suggestions", value="")
514
 
515
+ submit.click(fn=suggest, inputs=[yaml_input, threshold], outputs=output)
516
  # No auto-trigger on yaml_input.change — typing/pasting a long YAML would
517
  # fire many inference requests and back up the queue. Button click only.
518