Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -12,12 +12,26 @@ 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
 
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("Loading Hugging Face LLM pipeline...")
16
+ self.pipe = pipeline(
17
+ "text-generation",
18
+ model="mistralai/Mistral-7B-Instruct-v0.1",
19
+ device=0 if torch.cuda.is_available() else -1,
20
+ max_new_tokens=256,
21
+ do_sample=True,
22
+ temperature=0.7
23
+ )
24
+
25
  def __call__(self, question: str) -> str:
26
+ prompt = f"[INST] {question.strip()} [/INST]"
27
+ try:
28
+ response = self.pipe(prompt)[0]["generated_text"]
29
+ # Post-processing to trim the prompt out of the response
30
+ answer = response.replace(prompt, "").strip()
31
+ print(f"Generated Answer: {answer[:80]}...")
32
+ return answer
33
+ except Exception as e:
34
+ return f"Error: {e}"
35
 
36
  def run_and_submit_all( profile: gr.OAuthProfile | None):
37
  """