Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -8,28 +8,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
8
 
9
 
10
  # --- FIXED BASIC AGENT ---
 
 
11
  class BasicAgent:
12
  def __init__(self):
13
- print("Agent initialized")
14
 
15
  def __call__(self, question: str) -> str:
16
- try:
17
- # Simple fallback logic (so it NEVER returns "unknown")
18
- question = question.lower()
19
-
20
- # very basic handling so you get non-zero score baseline
21
- if "how many" in question:
22
- return "unknown" # replace later with real logic if needed
23
-
24
- if "opposite" in question:
25
- return "left"
26
 
27
- # default safe answer (prevents empty failures)
28
- return "unknown"
29
 
30
- except Exception as e:
31
- print(f"Agent error: {e}")
32
- return "unknown"
33
 
34
 
35
  def run_and_submit_all(profile: gr.OAuthProfile | None):
 
8
 
9
 
10
  # --- FIXED BASIC AGENT ---
11
+ from transformers import pipeline
12
+
13
  class BasicAgent:
14
  def __init__(self):
15
+ self.model = pipeline("text-generation", model="gpt2")
16
 
17
  def __call__(self, question: str) -> str:
18
+ prompt = (
19
+ "Answer ONLY with the final short result.\n"
20
+ "No explanation.\n\n"
21
+ f"Question: {question}\nAnswer:"
22
+ )
 
 
 
 
 
23
 
24
+ output = self.model(prompt, max_new_tokens=50, do_sample=False)[0]["generated_text"]
 
25
 
26
+ # extract only answer part
27
+ return output.split("Answer:")[-1].strip().split("\n")[0]
 
28
 
29
 
30
  def run_and_submit_all(profile: gr.OAuthProfile | None):