taruschirag commited on
Commit
f1857ae
·
verified ·
1 Parent(s): 74ee998

Update app.py

Browse files

fixed the enumeration and the reasoning bug.

Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -40,11 +40,10 @@ Few sentences of reasoning
40
  """
41
 
42
  # --- Helper Functions ---
43
- def format_rules(rules):
44
- formatted_rules = "<rules>\n"
45
- for i, rule in enumerate(rules):
46
- formatted_rules += f"{i + 1}. {rule}\n"
47
- formatted_rules += "</rules>\n"
48
  return formatted_rules
49
 
50
  def format_transcript(transcript):
@@ -57,7 +56,7 @@ def format_output(text):
57
  explanation = re.search(r"<explanation>(.*?)</explanation>", text, flags=re.DOTALL)
58
 
59
  display = ""
60
- if think_match and len(reasoning.group(1).strip()) > 1:
61
  display += "Reasoning:\n" + reasoning.group(1).strip() + "\n\n"
62
  if answer:
63
  display += "Answer:\n" + answer.group(1).strip() + "\n\n"
@@ -187,7 +186,6 @@ def get_model(model_name):
187
  def compliance_check(rules_text, transcript_text, thinking, model_name):
188
  try:
189
  model = get_model(model_name)
190
- rules = [r for r in rules_text.split("\n") if r.strip()]
191
  inp = format_rules(rules) + format_transcript(transcript_text)
192
 
193
  out = model.get_response(inp, enable_thinking=thinking, max_new_tokens=256)
@@ -212,10 +210,10 @@ with gr.Blocks(title="DynaGuard Compliance Checker") as demo:
212
  with gr.Tab("Compliance Checker"):
213
  rules_box = gr.Textbox(
214
  lines=5,
215
- label="Rules (one per line)",
216
- value="""Show all steps when helping a user with math problems.
217
- Ask at least one question before providing an answer to homework questions.
218
- Do not use sarcasm.
219
  """
220
  )
221
  transcript_box = gr.Textbox(
 
40
  """
41
 
42
  # --- Helper Functions ---
43
+
44
+ def format_rules(rules_text):
45
+ """Wraps the raw text from the rules textbox with the required tags."""
46
+ formatted_rules = f"<rules>\n{rules_text.strip()}\n</rules>\n"
 
47
  return formatted_rules
48
 
49
  def format_transcript(transcript):
 
56
  explanation = re.search(r"<explanation>(.*?)</explanation>", text, flags=re.DOTALL)
57
 
58
  display = ""
59
+ if reasoning and len(reasoning.group(1).strip()) > 1:
60
  display += "Reasoning:\n" + reasoning.group(1).strip() + "\n\n"
61
  if answer:
62
  display += "Answer:\n" + answer.group(1).strip() + "\n\n"
 
186
  def compliance_check(rules_text, transcript_text, thinking, model_name):
187
  try:
188
  model = get_model(model_name)
 
189
  inp = format_rules(rules) + format_transcript(transcript_text)
190
 
191
  out = model.get_response(inp, enable_thinking=thinking, max_new_tokens=256)
 
210
  with gr.Tab("Compliance Checker"):
211
  rules_box = gr.Textbox(
212
  lines=5,
213
+ label="Rules (one per line, numbered)",
214
+ value="""1. Show all steps when helping a user with math problems.
215
+ 2. Ask at least one question before providing an answer to homework questions.
216
+ 3. Do not use sarcasm.
217
  """
218
  )
219
  transcript_box = gr.Textbox(