Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ from huggingface_hub import InferenceClient, login
|
|
18 |
|
19 |
class BasicAgent:
|
20 |
def __init__(self):
|
21 |
-
login(token=os.environ["HF_TOKEN"])
|
22 |
|
23 |
self.client = InferenceClient(
|
24 |
model="Qwen/Qwen2-7B-Instruct",
|
@@ -26,6 +26,11 @@ class BasicAgent:
|
|
26 |
timeout=120
|
27 |
)
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
def __call__(self, question: str) -> str:
|
30 |
try:
|
31 |
prompt = f"""<|im_start|>system
|
@@ -37,14 +42,15 @@ Answer with ONLY the exact value requested.<|im_end|>
|
|
37 |
response = self.client.text_generation(
|
38 |
prompt=prompt,
|
39 |
temperature=0.01,
|
40 |
-
max_new_tokens=
|
41 |
-
stop_sequences=["<|im_end|>"]
|
|
|
42 |
)
|
43 |
return response.split("<|im_start|>assistant")[-1].split("<|im_end|>")[0].strip()
|
44 |
-
except Exception:
|
|
|
45 |
return ""
|
46 |
|
47 |
-
|
48 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
49 |
"""
|
50 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
18 |
|
19 |
class BasicAgent:
|
20 |
def __init__(self):
|
21 |
+
login(token=os.environ["HF_TOKEN"])
|
22 |
|
23 |
self.client = InferenceClient(
|
24 |
model="Qwen/Qwen2-7B-Instruct",
|
|
|
26 |
timeout=120
|
27 |
)
|
28 |
|
29 |
+
# Verify model access
|
30 |
+
test_response = self.client.text_generation("2+2=", max_new_tokens=10)
|
31 |
+
if "4" not in test_response:
|
32 |
+
raise RuntimeError(f"Model test failed: {test_response}")
|
33 |
+
|
34 |
def __call__(self, question: str) -> str:
|
35 |
try:
|
36 |
prompt = f"""<|im_start|>system
|
|
|
42 |
response = self.client.text_generation(
|
43 |
prompt=prompt,
|
44 |
temperature=0.01,
|
45 |
+
max_new_tokens=100,
|
46 |
+
stop_sequences=["<|im_end|>"],
|
47 |
+
repetition_penalty=1.1
|
48 |
)
|
49 |
return response.split("<|im_start|>assistant")[-1].split("<|im_end|>")[0].strip()
|
50 |
+
except Exception as e:
|
51 |
+
print(f"Error processing '{question[:50]}...': {str(e)}")
|
52 |
return ""
|
53 |
|
|
|
54 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
55 |
"""
|
56 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|