Ubik80 commited on
Commit
03a058f
·
verified ·
1 Parent(s): 21325a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -26
app.py CHANGED
@@ -11,7 +11,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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(
@@ -22,19 +22,14 @@ class BasicAgent:
22
  )
23
 
24
  def __call__(self, question: str) -> str:
 
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
 
39
  # Fetch questions
40
  try:
@@ -51,7 +46,7 @@ def run_and_submit_all(profile):
51
  for q in questions:
52
  tid = q.get('task_id')
53
  text = q.get('question')
54
- if not tid or not text:
55
  continue
56
  try:
57
  ans = agent(text)
@@ -85,15 +80,7 @@ def run_and_submit_all(profile):
85
  return status, pd.DataFrame(results)
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:
98
  q = requests.get(f"{DEFAULT_API_URL}/random-question", timeout=15).json()
99
  ans = BasicAgent()(q.get('question', ''))
@@ -107,13 +94,13 @@ with gr.Blocks() as demo:
107
  gr.Markdown(
108
  """
109
  **Instructions:**
110
- 1. Clone this space and define your agent in `tools.py`.
111
- 2. Log in with your Hugging Face account.
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
 
@@ -122,8 +109,8 @@ with gr.Blocks() as demo:
122
  question_out = gr.Textbox(label="Random Question", lines=3, interactive=False)
123
  answer_out = gr.Textbox(label="Agent Answer", lines=3, interactive=False)
124
 
125
- run_btn.click(fn=run_and_submit_all, inputs=[login], outputs=[status_out, table_out])
126
- test_btn.click(fn=test_random_question, inputs=[login], outputs=[question_out, answer_out])
127
 
128
  if __name__ == "__main__":
129
  demo.launch(debug=True, share=False)
 
11
 
12
  class BasicAgent:
13
  def __init__(self):
14
+ # Use GPT-4o; ensure your OpenAI API key has access
15
  model = OpenAIServerModel(model_id="gpt-4o")
16
  final_tool = FinalAnswerTool()
17
  self.agent = CodeAgent(
 
22
  )
23
 
24
  def __call__(self, question: str) -> str:
25
+ # Positional call
26
  return self.agent.run(question)
27
 
28
 
29
+ def run_and_submit_all(username):
30
+ # Username provided manually by the user
 
 
 
 
 
 
31
  if not username:
32
+ return "Please enter your Hugging Face username.", None
33
 
34
  # Fetch questions
35
  try:
 
46
  for q in questions:
47
  tid = q.get('task_id')
48
  text = q.get('question')
49
+ if not (tid and text):
50
  continue
51
  try:
52
  ans = agent(text)
 
80
  return status, pd.DataFrame(results)
81
 
82
 
83
+ def test_random_question():
 
 
 
 
 
 
 
 
84
  try:
85
  q = requests.get(f"{DEFAULT_API_URL}/random-question", timeout=15).json()
86
  ans = BasicAgent()(q.get('question', ''))
 
94
  gr.Markdown(
95
  """
96
  **Instructions:**
97
+ 1. Enter your Hugging Face username.
98
+ 2. Use **Test Random Question** to check a single question.
99
+ 3. Use **Run Evaluation & Submit All Answers** to evaluate on all questions.
100
  """
101
  )
102
 
103
+ username_input = gr.Textbox(label="Hugging Face Username", placeholder="your-username")
104
  run_btn = gr.Button("Run Evaluation & Submit All Answers")
105
  test_btn = gr.Button("Test Random Question")
106
 
 
109
  question_out = gr.Textbox(label="Random Question", lines=3, interactive=False)
110
  answer_out = gr.Textbox(label="Agent Answer", lines=3, interactive=False)
111
 
112
+ run_btn.click(fn=run_and_submit_all, inputs=[username_input], outputs=[status_out, table_out])
113
+ test_btn.click(fn=test_random_question, inputs=[], outputs=[question_out, answer_out])
114
 
115
  if __name__ == "__main__":
116
  demo.launch(debug=True, share=False)