Update app.py
Browse filesUpdated code for testing login
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 |
-
|
| 7 |
-
|
| 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 |
-
|
| 17 |
-
|
| 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 |
-
|
| 50 |
-
|
| 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 |
-
|
| 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 |
-
|
| 65 |
|
| 66 |
|
| 67 |
# --- Build Gradio Interface using Blocks ---
|
|
@@ -71,15 +70,15 @@ with gr.Blocks() as demo:
|
|
| 71 |
"""
|
| 72 |
**Instructions:**
|
| 73 |
|
| 74 |
-
1.
|
| 75 |
-
2. Click '
|
| 76 |
-
3. Click 'Submit All Answers' to
|
| 77 |
|
| 78 |
---
|
| 79 |
**Disclaimers:**
|
| 80 |
-
Once clicking '
|
| 81 |
-
The agent will run
|
| 82 |
-
The
|
| 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,
|