ayushi006 commited on
Commit
3edb6a5
·
verified ·
1 Parent(s): 81917a3

update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -12,10 +12,33 @@ 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("BasicAgent initialized.")
16
  def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  print(f"Agent returning fixed answer: {fixed_answer}")
20
  return fixed_answer
21
 
 
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
15
+ print("SmartAgent initialized.")
16
  def __call__(self, question: str) -> str:
17
+ print(f"Agent received: {question[:50]}...")
18
+ #solve simple maths question
19
+
20
+ maths = re.findall(r"(\d+)\s*([\+\-\*/])\s*(\d+)", question)
21
+ if maths:
22
+ a, op, b = maths[0]
23
+ a, b = int(a), int(b)
24
+ if op == "+": return str(a + b)
25
+ if op == "-": return str(a - b)
26
+ if op == "*": return str(a * b)
27
+ if op == "/": return str(a / b)
28
+
29
+ # Example 2: Factorial question
30
+ if "factorial" in question.lower():
31
+ num = int(re.search(r"\d+", question).group())
32
+ return str(math.factorial(num))
33
+
34
+ # Example 3: Reverse string
35
+ if "reverse" in question.lower():
36
+ word = question.split()[-1]
37
+ return word[::-1]
38
+
39
+
40
+
41
+ fixed_answer = "Sorry, I dont know yet"
42
  print(f"Agent returning fixed answer: {fixed_answer}")
43
  return fixed_answer
44