Update app.py
Browse files
app.py
CHANGED
|
@@ -119,7 +119,7 @@ def solve_polynomial(image, llm_url):
|
|
| 119 |
root_strs.append(str(root_val))
|
| 120 |
output += "\\end{aligned}\n$$\n"
|
| 121 |
|
| 122 |
-
#
|
| 123 |
prompt = ""
|
| 124 |
try:
|
| 125 |
coeffs = sp.Poly(lhs, x).all_coeffs()
|
|
@@ -137,10 +137,10 @@ def solve_polynomial(image, llm_url):
|
|
| 137 |
f"Equation: {lhs} = 0\n"
|
| 138 |
f"Factor: {factor} = 0\n"
|
| 139 |
f"Roots: {root_strs}\n\n"
|
| 140 |
-
f"
|
| 141 |
f"a = {a}, b = {b}, c = {c}, a*c = {prod}. "
|
| 142 |
f"{m} and {n} satisfy m*n = ac and m+n = b.\n"
|
| 143 |
-
f"Explain
|
| 144 |
)
|
| 145 |
break
|
| 146 |
if not found:
|
|
@@ -152,9 +152,8 @@ def solve_polynomial(image, llm_url):
|
|
| 152 |
f"Equation: {lhs} = 0\n"
|
| 153 |
f"Factor: {factor} = 0\n"
|
| 154 |
f"Roots: {root_strs}\n\n"
|
| 155 |
-
f"
|
| 156 |
-
f"
|
| 157 |
-
f"Explain this step-by-step.\n<|end|>"
|
| 158 |
)
|
| 159 |
|
| 160 |
return output, cleaned_latex, prompt
|
|
@@ -197,7 +196,8 @@ def solve_from_coeffs(degree, coeff_str):
|
|
| 197 |
f"Equation: {equation_str}\n"
|
| 198 |
f"Factor: {factored_str} = 0\n"
|
| 199 |
f"Roots: {roots_str}\n\n"
|
| 200 |
-
|
|
|
|
| 201 |
)
|
| 202 |
|
| 203 |
return result, llm_prompt
|
|
|
|
| 119 |
root_strs.append(str(root_val))
|
| 120 |
output += "\\end{aligned}\n$$\n"
|
| 121 |
|
| 122 |
+
# 👇 Build structured prompt
|
| 123 |
prompt = ""
|
| 124 |
try:
|
| 125 |
coeffs = sp.Poly(lhs, x).all_coeffs()
|
|
|
|
| 137 |
f"Equation: {lhs} = 0\n"
|
| 138 |
f"Factor: {factor} = 0\n"
|
| 139 |
f"Roots: {root_strs}\n\n"
|
| 140 |
+
f"This was solved using middle-term factorization:\n"
|
| 141 |
f"a = {a}, b = {b}, c = {c}, a*c = {prod}. "
|
| 142 |
f"{m} and {n} satisfy m*n = ac and m+n = b.\n"
|
| 143 |
+
f"Explain the process step-by-step in friendly, simple language."
|
| 144 |
)
|
| 145 |
break
|
| 146 |
if not found:
|
|
|
|
| 152 |
f"Equation: {lhs} = 0\n"
|
| 153 |
f"Factor: {factor} = 0\n"
|
| 154 |
f"Roots: {root_strs}\n\n"
|
| 155 |
+
f"This was solved using the quadratic formula (Sreedhar Acharya method). "
|
| 156 |
+
f"Explain the process step-by-step in friendly, simple language."
|
|
|
|
| 157 |
)
|
| 158 |
|
| 159 |
return output, cleaned_latex, prompt
|
|
|
|
| 196 |
f"Equation: {equation_str}\n"
|
| 197 |
f"Factor: {factored_str} = 0\n"
|
| 198 |
f"Roots: {roots_str}\n\n"
|
| 199 |
+
"Explain the solution step-by-step in human language. "
|
| 200 |
+
"These roots are correct (up to approximation), so base your reasoning on them."
|
| 201 |
)
|
| 202 |
|
| 203 |
return result, llm_prompt
|