Yongkang ZOU commited on
Commit
9348b59
·
1 Parent(s): 19dc6ec

update app

Browse files
Files changed (1) hide show
  1. app.py +12 -20
app.py CHANGED
@@ -16,16 +16,11 @@ class BasicAgent:
16
  print(f"Agent returning fixed answer: {fixed_answer}")
17
  return fixed_answer
18
 
19
- def run_and_submit_all(profile: gr.OAuthProfile | None):
20
- space_id = os.getenv("SPACE_ID")
21
-
22
- if profile and profile.username:
23
- username = profile.username
24
- print(f"User logged in: {username}")
25
- else:
26
- print("User not logged in.")
27
- return "Please Login to Hugging Face with the button.", None
28
 
 
29
  api_url = DEFAULT_API_URL
30
  questions_url = f"{api_url}/questions"
31
  submit_url = f"{api_url}/submit"
@@ -35,8 +30,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
35
  except Exception as e:
36
  return f"Error initializing agent: {e}", None
37
 
38
- agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
39
- print(agent_code)
40
 
41
  print(f"Fetching questions from: {questions_url}")
42
  try:
@@ -79,7 +73,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
79
  response.raise_for_status()
80
  result_data = response.json()
81
  final_status = (
82
- f"Submission Successful!\n"
83
  f"User: {result_data.get('username')}\n"
84
  f"Overall Score: {result_data.get('score', 'N/A')}% "
85
  f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
@@ -88,23 +82,21 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
88
  results_df = pd.DataFrame(results_log)
89
  return final_status, results_df
90
  except Exception as e:
91
- return f"Submission Failed: {e}", pd.DataFrame(results_log)
92
 
93
- # --- Build Gradio Interface using Blocks ---
94
  with gr.Blocks() as demo:
95
  gr.Markdown("# Basic Agent Evaluation Runner")
96
  gr.Markdown(
97
  """
98
  **Instructions:**
99
- 1. Please clone this space, then modify the code to define your agent's logic, tools, etc.
100
- 2. Log in to Hugging Face using the button below.
101
- 3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and get your score.
102
  ---
103
  """
104
  )
105
 
106
- gr.LoginButton()
107
- user_profile = gr.OAuthProfile()
108
 
109
  run_button = gr.Button("Run Evaluation & Submit All Answers")
110
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
@@ -112,7 +104,7 @@ with gr.Blocks() as demo:
112
 
113
  run_button.click(
114
  fn=run_and_submit_all,
115
- inputs=[user_profile], # ✅ 关键:将登录信息传给函数
116
  outputs=[status_output, results_table]
117
  )
118
 
 
16
  print(f"Agent returning fixed answer: {fixed_answer}")
17
  return fixed_answer
18
 
19
+ def run_and_submit_all(username: str):
20
+ if not username:
21
+ return "❌ Please enter your Hugging Face username.", None
 
 
 
 
 
 
22
 
23
+ space_id = os.getenv("SPACE_ID")
24
  api_url = DEFAULT_API_URL
25
  questions_url = f"{api_url}/questions"
26
  submit_url = f"{api_url}/submit"
 
30
  except Exception as e:
31
  return f"Error initializing agent: {e}", None
32
 
33
+ agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else "N/A"
 
34
 
35
  print(f"Fetching questions from: {questions_url}")
36
  try:
 
73
  response.raise_for_status()
74
  result_data = response.json()
75
  final_status = (
76
+ f"Submission Successful!\n"
77
  f"User: {result_data.get('username')}\n"
78
  f"Overall Score: {result_data.get('score', 'N/A')}% "
79
  f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
 
82
  results_df = pd.DataFrame(results_log)
83
  return final_status, results_df
84
  except Exception as e:
85
+ return f"Submission Failed: {e}", pd.DataFrame(results_log)
86
 
87
+ # --- Gradio Interface ---
88
  with gr.Blocks() as demo:
89
  gr.Markdown("# Basic Agent Evaluation Runner")
90
  gr.Markdown(
91
  """
92
  **Instructions:**
93
+ 1. Please enter your Hugging Face username below manually.
94
+ 2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see your score.
 
95
  ---
96
  """
97
  )
98
 
99
+ username_box = gr.Textbox(label="Your Hugging Face Username (for submission)", placeholder="e.g. johndoe")
 
100
 
101
  run_button = gr.Button("Run Evaluation & Submit All Answers")
102
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
 
104
 
105
  run_button.click(
106
  fn=run_and_submit_all,
107
+ inputs=[username_box],
108
  outputs=[status_output, results_table]
109
  )
110