Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,13 +11,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
-
def __init__(self):
|
15 |
-
print("
|
|
|
|
|
16 |
def __call__(self, question: str) -> str:
|
17 |
-
print(f"
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
@@ -40,7 +50,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
40 |
|
41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
42 |
try:
|
43 |
-
|
|
|
44 |
except Exception as e:
|
45 |
print(f"Error instantiating agent: {e}")
|
46 |
return f"Error initializing agent: {e}", None
|
|
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
class BasicAgent:
|
14 |
+
def __init__(self, hf_token: str):
|
15 |
+
print("Advanced Agent initialized.")
|
16 |
+
self.client = InferenceClient(token=hf_token)
|
17 |
+
|
18 |
def __call__(self, question: str) -> str:
|
19 |
+
print(f"Processing question: {question[:50]}...")
|
20 |
+
|
21 |
+
response = self.client.text_generation(
|
22 |
+
prompt=f"GAIA Question: {question}\nAnswer:",
|
23 |
+
model="meta-llama/Llama-3-70B-Instruct",
|
24 |
+
temperature=0.3,
|
25 |
+
max_new_tokens=512,
|
26 |
+
repetition_penalty=1.1
|
27 |
+
)
|
28 |
+
|
29 |
+
print(f"Generated answer: {response[:50]}...")
|
30 |
+
return response
|
31 |
|
32 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
33 |
"""
|
|
|
50 |
|
51 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
52 |
try:
|
53 |
+
hf_token = os.getenv("HF_TOKEN") # Set this in Space settings
|
54 |
+
agent = BasicAgent(hf_token=hf_token)
|
55 |
except Exception as e:
|
56 |
print(f"Error instantiating agent: {e}")
|
57 |
return f"Error initializing agent: {e}", None
|