Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,8 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
11 |
|
12 |
class BasicAgent:
|
13 |
def __init__(self):
|
14 |
-
# Use GPT-
|
15 |
-
model = OpenAIServerModel(model_id="gpt-
|
16 |
final_tool = FinalAnswerTool()
|
17 |
self.agent = CodeAgent(
|
18 |
model=model,
|
@@ -25,24 +25,14 @@ class BasicAgent:
|
|
25 |
return self.agent.run(question)
|
26 |
|
27 |
|
28 |
-
def extract_username(profile):
|
29 |
-
"""
|
30 |
-
Extract username from the Hugging Face OAuthProfile or dict.
|
31 |
-
"""
|
32 |
-
if not profile:
|
33 |
-
return None
|
34 |
-
# If profile is a dict (Gradio may return dict), extract keys
|
35 |
-
if isinstance(profile, dict):
|
36 |
-
return profile.get('username') or profile.get('name') or profile.get('login') or profile.get('id')
|
37 |
-
# Otherwise, assume object with attributes
|
38 |
-
return getattr(profile, 'username', None) or getattr(profile, 'name', None) or getattr(profile, 'login', None)
|
39 |
-
|
40 |
-
|
41 |
def run_and_submit_all(profile):
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
46 |
if not username:
|
47 |
return "Please login to Hugging Face with the login button.", None
|
48 |
|
@@ -54,7 +44,7 @@ def run_and_submit_all(profile):
|
|
54 |
except Exception as e:
|
55 |
return f"Error fetching questions: {e}", None
|
56 |
|
57 |
-
# Run agent
|
58 |
agent = BasicAgent()
|
59 |
results = []
|
60 |
payload = []
|
@@ -73,7 +63,7 @@ def run_and_submit_all(profile):
|
|
73 |
if not payload:
|
74 |
return "Agent returned no answers.", pd.DataFrame(results)
|
75 |
|
76 |
-
#
|
77 |
submission = {
|
78 |
'username': username,
|
79 |
'agent_code': f"https://huggingface.co/spaces/{os.getenv('SPACE_ID')}/tree/main",
|
@@ -96,10 +86,12 @@ def run_and_submit_all(profile):
|
|
96 |
|
97 |
|
98 |
def test_random_question(profile):
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
|
|
103 |
if not username:
|
104 |
return "Please login to Hugging Face with the login button.", ""
|
105 |
try:
|
@@ -120,9 +112,11 @@ with gr.Blocks() as demo:
|
|
120 |
3. Use **Run Evaluation & Submit All Answers** or **Test Random Question**.
|
121 |
"""
|
122 |
)
|
|
|
123 |
login = gr.LoginButton()
|
124 |
run_btn = gr.Button("Run Evaluation & Submit All Answers")
|
125 |
test_btn = gr.Button("Test Random Question")
|
|
|
126 |
status_out = gr.Textbox(label="Status / Result", lines=5, interactive=False)
|
127 |
table_out = gr.DataFrame(label="Full Results Table", wrap=True)
|
128 |
question_out = gr.Textbox(label="Random Question", lines=3, interactive=False)
|
|
|
11 |
|
12 |
class BasicAgent:
|
13 |
def __init__(self):
|
14 |
+
# Use GPT-4o; ensure your API key has access
|
15 |
+
model = OpenAIServerModel(model_id="gpt-4o")
|
16 |
final_tool = FinalAnswerTool()
|
17 |
self.agent = CodeAgent(
|
18 |
model=model,
|
|
|
25 |
return self.agent.run(question)
|
26 |
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
def run_and_submit_all(profile):
|
29 |
+
# Extract username
|
30 |
+
username = None
|
31 |
+
if profile:
|
32 |
+
if isinstance(profile, dict):
|
33 |
+
username = profile.get('username') or profile.get('name') or profile.get('login') or profile.get('id')
|
34 |
+
else:
|
35 |
+
username = getattr(profile, 'username', None) or getattr(profile, 'name', None)
|
36 |
if not username:
|
37 |
return "Please login to Hugging Face with the login button.", None
|
38 |
|
|
|
44 |
except Exception as e:
|
45 |
return f"Error fetching questions: {e}", None
|
46 |
|
47 |
+
# Run agent
|
48 |
agent = BasicAgent()
|
49 |
results = []
|
50 |
payload = []
|
|
|
63 |
if not payload:
|
64 |
return "Agent returned no answers.", pd.DataFrame(results)
|
65 |
|
66 |
+
# Submit
|
67 |
submission = {
|
68 |
'username': username,
|
69 |
'agent_code': f"https://huggingface.co/spaces/{os.getenv('SPACE_ID')}/tree/main",
|
|
|
86 |
|
87 |
|
88 |
def test_random_question(profile):
|
89 |
+
username = None
|
90 |
+
if profile:
|
91 |
+
if isinstance(profile, dict):
|
92 |
+
username = profile.get('username') or profile.get('name')
|
93 |
+
else:
|
94 |
+
username = getattr(profile, 'username', None) or getattr(profile, 'name', None)
|
95 |
if not username:
|
96 |
return "Please login to Hugging Face with the login button.", ""
|
97 |
try:
|
|
|
112 |
3. Use **Run Evaluation & Submit All Answers** or **Test Random Question**.
|
113 |
"""
|
114 |
)
|
115 |
+
|
116 |
login = gr.LoginButton()
|
117 |
run_btn = gr.Button("Run Evaluation & Submit All Answers")
|
118 |
test_btn = gr.Button("Test Random Question")
|
119 |
+
|
120 |
status_out = gr.Textbox(label="Status / Result", lines=5, interactive=False)
|
121 |
table_out = gr.DataFrame(label="Full Results Table", wrap=True)
|
122 |
question_out = gr.Textbox(label="Random Question", lines=3, interactive=False)
|