Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 21 |
login(token=hf_token, add_to_git_credential=False)
|
| 22 |
|
| 23 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
self.client = InferenceClient(
|
| 25 |
model="meta-llama/Meta-Llama-3-70B-Instruct",
|
| 26 |
token=hf_token,
|
| 27 |
-
timeout=
|
| 28 |
)
|
| 29 |
|
| 30 |
def __call__(self, question: str) -> str:
|
| 31 |
try:
|
| 32 |
response = self.client.text_generation(
|
| 33 |
-
prompt=f"GAIA
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
| 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):
|