Spaces:
Sleeping
Sleeping
Update backend.py
Browse files- backend.py +11 -9
backend.py
CHANGED
|
@@ -16,26 +16,28 @@ def extract_final_answer(text):
|
|
| 16 |
if not text:
|
| 17 |
return None
|
| 18 |
|
| 19 |
-
# ✅
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
if match_dollars:
|
| 22 |
return match_dollars.group(1).strip()
|
| 23 |
|
| 24 |
-
# ✅
|
| 25 |
-
match_dollar = re.search(r'
|
| 26 |
if match_dollar:
|
| 27 |
return match_dollar.group(1).strip()
|
| 28 |
|
| 29 |
-
# ✅ Fallback: match plain text final answer line
|
| 30 |
-
match_plain = re.search(r'final answer[:\-]?\s*(.+)', text, re.IGNORECASE)
|
| 31 |
-
if match_plain:
|
| 32 |
-
return match_plain.group(1).strip()
|
| 33 |
-
|
| 34 |
# ✅ Final fallback: return last number
|
| 35 |
fallback = re.findall(r'\b\d+\.?\d*\b', text)
|
| 36 |
return fallback[-1].strip() if fallback else None
|
| 37 |
|
| 38 |
|
|
|
|
| 39 |
# Claude API call function
|
| 40 |
def call_claude(prompt):
|
| 41 |
headers = {
|
|
|
|
| 16 |
if not text:
|
| 17 |
return None
|
| 18 |
|
| 19 |
+
# ✅ Match full final answer line first (for things like: Final Answer: $x = 3$ or $x = 2$)
|
| 20 |
+
match_full = re.search(r'final answer[:\-]?\s*(.*)', text, re.IGNORECASE)
|
| 21 |
+
if match_full:
|
| 22 |
+
answer = match_full.group(1).strip()
|
| 23 |
+
if answer: return answer
|
| 24 |
+
|
| 25 |
+
# ✅ Match LaTeX-style $$...$$ if used alone
|
| 26 |
+
match_dollars = re.search(r'\$\$(.+?)\$\$', text)
|
| 27 |
if match_dollars:
|
| 28 |
return match_dollars.group(1).strip()
|
| 29 |
|
| 30 |
+
# ✅ Match LaTeX-style $...$ if used alone
|
| 31 |
+
match_dollar = re.search(r'\$(.+?)\$', text)
|
| 32 |
if match_dollar:
|
| 33 |
return match_dollar.group(1).strip()
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# ✅ Final fallback: return last number
|
| 36 |
fallback = re.findall(r'\b\d+\.?\d*\b', text)
|
| 37 |
return fallback[-1].strip() if fallback else None
|
| 38 |
|
| 39 |
|
| 40 |
+
|
| 41 |
# Claude API call function
|
| 42 |
def call_claude(prompt):
|
| 43 |
headers = {
|