0r0b0r0s commited on
Commit
63affe0
·
verified ·
1 Parent(s): 6eaf9f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -16,40 +16,36 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
  from huggingface_hub import InferenceClient, login
17
 
18
  class BasicAgent:
19
-
20
  def __init__(self, hf_token: str):
21
- # Required for gated models
22
  login(token=hf_token, add_to_git_credential=False)
23
-
24
- # Initialize HfApi client
25
  self.hf_api = HfApi(token=hf_token)
26
 
27
  # Verify model access
28
  try:
29
- model_info = self.hf_api.model_info(
30
- repo_id="meta-llama/Meta-Llama-3-70B-Instruct"
31
- )
32
- if model_info.gated:
33
- print("Verified Llama-3 access")
34
  except Exception as e:
35
- raise RuntimeError(f"Model access denied: {str(e)}")
36
-
 
 
 
 
 
 
 
37
  def __call__(self, question: str) -> str:
38
  try:
39
  response = self.client.text_generation(
40
- prompt=f"""GAIA RESPONSE PROTOCOL
41
- Question: {question}
42
- Answer: [EXACT ANSWER ONLY, NO EXPLANATION]""",
43
  temperature=0.1,
44
  max_new_tokens=50
45
  )
46
- # Extract only the answer portion
47
  return response.split("Answer:")[-1].strip().split("\n")[0]
48
  except Exception:
49
- # Return empty string instead of error message
50
  return ""
51
 
52
 
 
53
  def run_and_submit_all( profile: gr.OAuthProfile | None):
54
  """
55
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
16
  from huggingface_hub import InferenceClient, login
17
 
18
  class BasicAgent:
 
19
  def __init__(self, hf_token: str):
 
20
  login(token=hf_token, add_to_git_credential=False)
 
 
21
  self.hf_api = HfApi(token=hf_token)
22
 
23
  # Verify model access
24
  try:
25
+ self.hf_api.model_info("meta-llama/Meta-Llama-3-70B-Instruct")
 
 
 
 
26
  except Exception as e:
27
+ raise RuntimeError(f"Model access failed: {str(e)}")
28
+
29
+ # Initialize inference client
30
+ self.client = InferenceClient(
31
+ model="meta-llama/Meta-Llama-3-70B-Instruct",
32
+ token=hf_token,
33
+ timeout=60
34
+ )
35
+
36
  def __call__(self, question: str) -> str:
37
  try:
38
  response = self.client.text_generation(
39
+ prompt=f"Question: {question}\nAnswer:",
 
 
40
  temperature=0.1,
41
  max_new_tokens=50
42
  )
 
43
  return response.split("Answer:")[-1].strip().split("\n")[0]
44
  except Exception:
 
45
  return ""
46
 
47
 
48
+
49
  def run_and_submit_all( profile: gr.OAuthProfile | None):
50
  """
51
  Fetches all questions, runs the BasicAgent on them, submits all answers,