pavan-d commited on
Commit
7126d91
Β·
verified Β·
1 Parent(s): be4b3ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -15,31 +15,30 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
  class BasicAgent:
17
  def __init__(self):
18
- print("πŸ”„ Loading HF LLM pipeline...")
19
  self.llm = pipeline(
20
  "text-generation",
21
- model="mistralai/Mistral-7B-Instruct-v0.2",
22
- tokenizer="mistralai/Mistral-7B-Instruct-v0.2",
23
  max_new_tokens=200,
24
  temperature=0,
25
- device=0 if torch.cuda.is_available() else -1 # Use GPU if available
26
  )
27
- print("βœ… LLM Loaded.")
28
 
29
  def __call__(self, question: str) -> str:
30
  print(f"πŸ€– Agent received question: {question}")
31
 
32
- # Format as instruction
33
- prompt = f"[INST] {question} [/INST]"
34
-
35
  try:
36
  output = self.llm(prompt)[0]["generated_text"]
37
- # Strip original prompt from output
38
- answer = output.replace(prompt, "").strip()
39
  print(f"βœ… Answer: {answer}")
40
  return answer
41
  except Exception as e:
42
- print(f"❌ Error: {e}")
43
  return "I don't know"
44
 
45
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
  class BasicAgent:
17
  def __init__(self):
18
+ print("πŸ”„ Loading Zephyr 7B...")
19
  self.llm = pipeline(
20
  "text-generation",
21
+ model="HuggingFaceH4/zephyr-7b-beta",
22
+ tokenizer="HuggingFaceH4/zephyr-7b-beta",
23
  max_new_tokens=200,
24
  temperature=0,
25
+ device=0 if torch.cuda.is_available() else -1
26
  )
27
+ print("βœ… Zephyr 7B Loaded.")
28
 
29
  def __call__(self, question: str) -> str:
30
  print(f"πŸ€– Agent received question: {question}")
31
 
32
+ prompt = f"<|system|>You are a helpful assistant.<|user|>{question}<|assistant|>"
33
+
 
34
  try:
35
  output = self.llm(prompt)[0]["generated_text"]
36
+ # Post-process to remove prompt from output
37
+ answer = output.split("<|assistant|>")[-1].strip()
38
  print(f"βœ… Answer: {answer}")
39
  return answer
40
  except Exception as e:
41
+ print(f"❌ Error generating response: {e}")
42
  return "I don't know"
43
 
44
  def run_and_submit_all( profile: gr.OAuthProfile | None):