rootacess commited on
Commit
7981904
·
1 Parent(s): 7a88569

mathprompter improvements

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. mathprompter.py +2 -6
app.py CHANGED
@@ -27,15 +27,15 @@ def run(token, question, method):
27
  gr.Code.update(value=generated_code, interactive=True), gr.Button.update(visible=True))
28
 
29
  elif method == "MathPrompter":
30
- exp_op, code_op, generated_code = solve_mp(question, token)
31
-
32
  if code_op is not None:
33
  ans = f"Answer from Expression execution: {exp_op} \nAnswer from Code execution: {code_op} "
34
- return ans, gr.Code.update(value=generated_code, interactive=True), gr.Button.update(visible=True)
35
  else:
36
  return (
37
  "Code execution failed, please review it from below and re-run it or try-asking again with more details",
38
- gr.Code.update(value=generated_code, interactive=True), gr.Button.update(visible=True))
39
 
40
  else:
41
  raise gr.Error("Please select the evaluating strategy from dropdown")
 
27
  gr.Code.update(value=generated_code, interactive=True), gr.Button.update(visible=True))
28
 
29
  elif method == "MathPrompter":
30
+ exp_op, code_op, generated_code, generated_exp = solve_mp(question, token)
31
+ display_value = generated_exp + "\n\n" + generated_code
32
  if code_op is not None:
33
  ans = f"Answer from Expression execution: {exp_op} \nAnswer from Code execution: {code_op} "
34
+ return ans, gr.Code.update(value=display_value, interactive=True), gr.Button.update(visible=True)
35
  else:
36
  return (
37
  "Code execution failed, please review it from below and re-run it or try-asking again with more details",
38
+ gr.Code.update(value=display_value, interactive=True), gr.Button.update(visible=True))
39
 
40
  else:
41
  raise gr.Error("Please select the evaluating strategy from dropdown")
mathprompter.py CHANGED
@@ -36,7 +36,6 @@ def generate_python_code(question, equation, param, token):
36
 
37
  def run(question, random_candidates, hps, token):
38
  question, var_map = generate_algebric_template(question)
39
- print(question)
40
 
41
  # generating the random candidates for arguments
42
  random_mapping = pd.DataFrame(columns=list(var_map.keys()))
@@ -105,7 +104,6 @@ def solve_mp(question, token):
105
  (expression, code), var_map = run(question, 5, hps, token)
106
  exp_op = None
107
  code_op = None
108
-
109
  try:
110
  # expression output
111
  for k, v in var_map.items():
@@ -115,13 +113,11 @@ def solve_mp(question, token):
115
 
116
  if "input(" in expression:
117
  raise Exception
118
-
119
  exp_op = run_code(expression)
120
  except:
121
  print("expression cannot be executed", expression)
122
  try:
123
  # code output
124
- print(code)
125
  parameters = code.split("\n")[0].split("def solution")[-1][1:-2].split(",")
126
  if '' in parameters:
127
  parameters.remove('')
@@ -137,6 +133,6 @@ def solve_mp(question, token):
137
  raise Exception
138
  code_op = run_code(code)
139
  except:
140
- return None, None, code
141
 
142
- return exp_op, code_op, code
 
36
 
37
  def run(question, random_candidates, hps, token):
38
  question, var_map = generate_algebric_template(question)
 
39
 
40
  # generating the random candidates for arguments
41
  random_mapping = pd.DataFrame(columns=list(var_map.keys()))
 
104
  (expression, code), var_map = run(question, 5, hps, token)
105
  exp_op = None
106
  code_op = None
 
107
  try:
108
  # expression output
109
  for k, v in var_map.items():
 
113
 
114
  if "input(" in expression:
115
  raise Exception
 
116
  exp_op = run_code(expression)
117
  except:
118
  print("expression cannot be executed", expression)
119
  try:
120
  # code output
 
121
  parameters = code.split("\n")[0].split("def solution")[-1][1:-2].split(",")
122
  if '' in parameters:
123
  parameters.remove('')
 
133
  raise Exception
134
  code_op = run_code(code)
135
  except:
136
+ return None, None, code, expression
137
 
138
+ return exp_op, code_op, code, expression