civerson916 commited on
Commit
324b202
·
verified ·
1 Parent(s): b8517f0

Update app.py

Browse files

Updated code for testing login

Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -3,8 +3,8 @@ from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExport
3
  from openinference.instrumentation.smolagents import SmolagentsInstrumentor
4
  from opentelemetry.sdk.trace import TracerProvider
5
  from opentelemetry import trace
6
- # from evaluator import Evaluator
7
- # from runner import Runner
8
  from settings import Settings
9
  import os
10
  import pandas as pd
@@ -13,8 +13,8 @@ import logging
13
  logging.basicConfig(level=logging.INFO, force=True)
14
  logger = logging.getLogger(__name__)
15
  settings = Settings()
16
- # evaluator = Evaluator(settings)
17
- # runner = Runner(settings)
18
 
19
 
20
  # Create a TracerProvider for OpenTelemetry
@@ -40,28 +40,27 @@ def user_logged_in(profile: gr.OAuthProfile):
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
 
66
 
67
  # --- Build Gradio Interface using Blocks ---
@@ -71,15 +70,15 @@ with gr.Blocks() as demo:
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,10 +94,10 @@ with gr.Blocks() as demo:
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,
 
3
  from openinference.instrumentation.smolagents import SmolagentsInstrumentor
4
  from opentelemetry.sdk.trace import TracerProvider
5
  from opentelemetry import trace
6
+ from evaluator import Evaluator
7
+ from runner import Runner
8
  from settings import Settings
9
  import os
10
  import pandas as pd
 
13
  logging.basicConfig(level=logging.INFO, force=True)
14
  logger = logging.getLogger(__name__)
15
  settings = Settings()
16
+ evaluator = Evaluator(settings)
17
+ runner = Runner(settings)
18
 
19
 
20
  # Create a TracerProvider for OpenTelemetry
 
40
  return False
41
 
42
  LOGIN_MESSAGE = "Please Login to Hugging Face with the button."
43
+ EMPTY_RESULTS_TABLE = pd.DataFrame(columns=['task_id', 'question', 'answer'])
44
 
45
  def run_one(profile: gr.OAuthProfile | None) -> pd.DataFrame:
46
  if not user_logged_in(profile):
47
+ return LOGIN_MESSAGE, EMPTY_RESULTS_TABLE
48
  # questions = [evaluator.get_one_question()]
49
+ # return "Answer one random question...", runner.run_agent(questions)
50
+ return "You are logged in.", EMPTY_RESULTS_TABLE
51
+
 
52
  def run_all(profile: gr.OAuthProfile | None) -> pd.DataFrame:
53
  if not user_logged_in:
54
+ return LOGIN_MESSAGE, EMPTY_RESULTS_TABLE
55
  # questions = evaluator.get_questions()
56
+ # return "Answer all 20 questions...", runner.run_agent(questions)
57
+ return "You are logged in.", EMPTY_RESULTS_TABLE
 
58
 
59
  def submit():
60
  if not user_logged_in:
61
  return LOGIN_MESSAGE
62
  # evaluator.submit_answers()
63
+ return "You are logged in.", EMPTY_RESULTS_TABLE
64
 
65
 
66
  # --- Build Gradio Interface using Blocks ---
 
70
  """
71
  **Instructions:**
72
 
73
+ 1. Log in to your Hugging Face account using the button below. This will NOT use your HF username for submission.
74
+ 2. Click 'Get One Answer' to fetch a ranodom question or 'Get All Answers' to run the agent.
75
+ 3. Click 'Submit All Answers' to submit answers for evaluation and see the score.
76
 
77
  ---
78
  **Disclaimers:**
79
+ Once clicking 'Get All Answers', it can take quite some time (this is the time for the agent to go through all 20 questions).
80
+ The agent will run question tasks in parallel making observability tools a must. Langfuse instrumentation has been configured.
81
+ The 'Submit All Answers' button will use the most recent agent answers cached in the space for your username.
82
  """
83
  )
84
 
 
94
  label="Questions and Agent Answers", wrap=True)
95
 
96
  run_one_button.click(
97
+ fn=run_one, outputs=[status_output, results_table]
98
  )
99
  run_all_button.click(
100
+ fn=run_all, outputs=[status_output, results_table]
101
  )
102
  submit_button.click(
103
  fn=submit,