civerson916 commited on
Commit
b8517f0
·
verified ·
1 Parent(s): 9ff29f9

Update app.py

Browse files

Restored the original profile check for login

Files changed (1) hide show
  1. app.py +33 -18
app.py CHANGED
@@ -30,20 +30,36 @@ tracer = trace.get_tracer(__name__)
30
  # Instrument smolagents with the configured provider
31
  SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
32
 
33
-
34
- def run(test_mode) -> pd.DataFrame:
35
- if test_mode:
36
- logger.info("test_mode")
37
- # questions = [evaluator.get_one_question()]
38
  else:
39
- logger.info("not test_mode")
40
- # questions = evaluator.get_questions()
41
-
 
 
 
 
 
 
42
  # return runner.run_agent(questions)
 
 
 
 
 
 
 
 
 
43
  return pd.DataFrame(columns=['task_id', 'question', 'answer'])
44
-
45
 
46
  def submit():
 
 
47
  # evaluator.submit_answers()
48
  logger.info("submit")
49
 
@@ -55,14 +71,15 @@ with gr.Blocks() as demo:
55
  """
56
  **Instructions:**
57
 
58
- 1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
59
- 2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
60
- 3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
61
 
62
  ---
63
  **Disclaimers:**
64
- Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
65
- This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
 
66
  """
67
  )
68
 
@@ -78,12 +95,10 @@ with gr.Blocks() as demo:
78
  label="Questions and Agent Answers", wrap=True)
79
 
80
  run_one_button.click(
81
- fn=run, inputs=[gr.Checkbox(value=True, visible=False)],
82
- outputs=[results_table]
83
  )
84
  run_all_button.click(
85
- fn=run, inputs=[gr.Checkbox(value=False, visible=False)],
86
- outputs=[results_table]
87
  )
88
  submit_button.click(
89
  fn=submit,
 
30
  # Instrument smolagents with the configured provider
31
  SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
32
 
33
+ def user_logged_in(profile: gr.OAuthProfile):
34
+ if profile:
35
+ username= f"{profile.username}"
36
+ print(f"User logged in: {username}")
37
+ return True
38
  else:
39
+ print("User not logged in.")
40
+ return False
41
+
42
+ LOGIN_MESSAGE = "Please Login to Hugging Face with the button."
43
+
44
+ def run_one(profile: gr.OAuthProfile | None) -> pd.DataFrame:
45
+ if not user_logged_in(profile):
46
+ return LOGIN_MESSAGE
47
+ # questions = [evaluator.get_one_question()]
48
  # return runner.run_agent(questions)
49
+ logger.info("test_mode")
50
+ return pd.DataFrame(columns=['task_id', 'question', 'answer'])
51
+
52
+ def run_all(profile: gr.OAuthProfile | None) -> pd.DataFrame:
53
+ if not user_logged_in:
54
+ return LOGIN_MESSAGE
55
+ # questions = evaluator.get_questions()
56
+ # return runner.run_agent(questions)
57
+ logger.info("not test_mode")
58
  return pd.DataFrame(columns=['task_id', 'question', 'answer'])
 
59
 
60
  def submit():
61
+ if not user_logged_in:
62
+ return LOGIN_MESSAGE
63
  # evaluator.submit_answers()
64
  logger.info("submit")
65
 
 
71
  """
72
  **Instructions:**
73
 
74
+ 1. Click 'Get One Answer' to fetch a ranodom question, run the agent, and see the question-answer pair below
75
+ 2. Click 'Run Full Evaluation' to fetch all question, run the agent, and see the question-answer pairs below
76
+ 3. Click 'Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
77
 
78
  ---
79
  **Disclaimers:**
80
+ Once clicking 'Submit All Answers', it can take quite some time (this is the time for the agent to go through all the questions).
81
+ The agent will run questions in parallel for the full evaluation, making observability tools a must.
82
+ The submit button will use the most recent agent answers cached in the space.
83
  """
84
  )
85
 
 
95
  label="Questions and Agent Answers", wrap=True)
96
 
97
  run_one_button.click(
98
+ fn=run_one, outputs=[results_table]
 
99
  )
100
  run_all_button.click(
101
+ fn=run_all, outputs=[results_table]
 
102
  )
103
  submit_button.click(
104
  fn=submit,