Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,12 +12,42 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
print("
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
print("Smart Agent Initialized")
|
| 16 |
+
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
+
"""
|
| 19 |
+
Simple reasoning agent with math solving and keyword matching.
|
| 20 |
+
"""
|
| 21 |
+
import re
|
| 22 |
+
|
| 23 |
+
question_lower = question.lower().strip()
|
| 24 |
+
|
| 25 |
+
# Math Solver - detect and evaluate arithmetic expressions
|
| 26 |
+
math_pattern = r'[-+]?\d*\.?\d+[\s]*[\+\-\*/][\s]*[-+]?\d*\.?\d+'
|
| 27 |
+
math_match = re.search(math_pattern, question)
|
| 28 |
+
|
| 29 |
+
if math_match:
|
| 30 |
+
try:
|
| 31 |
+
expr = math_match.group()
|
| 32 |
+
result = eval(expr)
|
| 33 |
+
if isinstance(result, float) and result.is_integer():
|
| 34 |
+
return str(int(result))
|
| 35 |
+
return str(result)
|
| 36 |
+
except:
|
| 37 |
+
pass
|
| 38 |
+
|
| 39 |
+
# Keyword-based QA
|
| 40 |
+
if "capital" in question_lower and "france" in question_lower:
|
| 41 |
+
return "Paris"
|
| 42 |
+
if "largest ocean" in question_lower:
|
| 43 |
+
return "Pacific Ocean"
|
| 44 |
+
if "2+2" in question_lower or "2 + 2" in question_lower:
|
| 45 |
+
return "4"
|
| 46 |
+
if "5+7" in question_lower or "5 + 7" in question_lower:
|
| 47 |
+
return "12"
|
| 48 |
+
|
| 49 |
+
# Fallback
|
| 50 |
+
return "I don't know"
|
| 51 |
|
| 52 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 53 |
"""
|