0r0b0r0s commited on
Commit
9c1383b
·
verified ·
1 Parent(s): 594a71c

Update app.py

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