Hanokh commited on
Commit
dd8708a
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files

did a very naive implemetation

Files changed (1) hide show
  1. app.py +72 -2
app.py CHANGED
@@ -13,10 +13,80 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
13
  class BasicAgent:
14
  def __init__(self):
15
  print("BasicAgent initialized.")
16
+
17
  def __call__(self, question: str) -> str:
18
  print(f"Agent received question (first 50 chars): {question[:50]}...")
19
+
20
+ # --- Addition ---
21
+ if match := re.match(r".*what is (\d+) \+ (\d+).*", question, re.IGNORECASE):
22
+ return str(int(match.group(1)) + int(match.group(2)))
23
+
24
+ # --- Multiplication ---
25
+ if match := re.match(r".*what is (\d+) \* (\d+).*", question, re.IGNORECASE):
26
+ return str(int(match.group(1)) * int(match.group(2)))
27
+
28
+ # --- Subtraction ---
29
+ if match := re.match(r".*what is (\d+) - (\d+).*", question, re.IGNORECASE):
30
+ return str(int(match.group(1)) - int(match.group(2)))
31
+
32
+ # --- Division ---
33
+ if match := re.match(r".*what is (\d+) / (\d+).*", question, re.IGNORECASE):
34
+ a, b = int(match.group(1)), int(match.group(2))
35
+ return str(a / b if b != 0 else "undefined")
36
+
37
+ # --- Factorial ---
38
+ if match := re.match(r".*factorial of (\d+).*", question, re.IGNORECASE):
39
+ return str(math.factorial(int(match.group(1))))
40
+
41
+ # --- Fibonacci ---
42
+ if match := re.match(r".*fibonacci of (\d+).*", question, re.IGNORECASE):
43
+ n = int(match.group(1))
44
+ def fib(n):
45
+ a, b = 0, 1
46
+ for _ in range(n):
47
+ a, b = b, a + b
48
+ return a
49
+ return str(fib(n))
50
+
51
+ # --- Prime check ---
52
+ if match := re.match(r".*is (\d+) prime.*", question, re.IGNORECASE):
53
+ n = int(match.group(1))
54
+ if n < 2:
55
+ return "no"
56
+ for i in range(2, int(math.sqrt(n)) + 1):
57
+ if n % i == 0:
58
+ return "no"
59
+ return "yes"
60
+
61
+ # --- Reverse string ---
62
+ if match := re.match(r".*reverse (?:the string )?'(.*)'.*", question, re.IGNORECASE):
63
+ return match.group(1)[::-1]
64
+
65
+ # --- Uppercase ---
66
+ if match := re.match(r".*uppercase of '(.*)'.*", question, re.IGNORECASE):
67
+ return match.group(1).upper()
68
+
69
+ # --- Lowercase ---
70
+ if match := re.match(r".*lowercase of '(.*)'.*", question, re.IGNORECASE):
71
+ return match.group(1).lower()
72
+
73
+ # --- Count words ---
74
+ if match := re.match(r".*count words in '(.*)'.*", question, re.IGNORECASE):
75
+ return str(len(match.group(1).split()))
76
+
77
+ # --- Count letters ---
78
+ if match := re.match(r".*count letters in '(.*)'.*", question, re.IGNORECASE):
79
+ return str(len(match.group(1)))
80
+
81
+ # --- Sort numbers ---
82
+ if match := re.match(r".*sort numbers (.*)", question, re.IGNORECASE):
83
+ numbers = re.findall(r"-?\d+", match.group(1))
84
+ sorted_nums = sorted(map(int, numbers))
85
+ return " ".join(map(str, sorted_nums))
86
+
87
+ # --- Default fallback ---
88
+ fixed_answer = "I don't know yet."
89
+ print(f"Agent returning fallback answer: {fixed_answer}")
90
  return fixed_answer
91
 
92
  def run_and_submit_all( profile: gr.OAuthProfile | None):