Spaces:
Running
Running
Ouz
commited on
Commit
·
ab0b62d
1
Parent(s):
3ebe57a
new button added
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from root import RootSignals
|
3 |
|
4 |
-
client = None
|
5 |
|
6 |
ROOT_EVALUATORS = ['Answer Correctness',
|
7 |
'Answer Relevance',
|
@@ -28,40 +28,42 @@ ROOT_EVALUATORS = ['Answer Correctness',
|
|
28 |
def initialize_client(api_key):
|
29 |
global client
|
30 |
client = RootSignals(api_key=api_key)
|
31 |
-
return gr.Dropdown(choices=ROOT_EVALUATORS)
|
32 |
|
33 |
def process_and_evaluate(api_key, user_input, llm_response, selected_evaluator):
|
34 |
global client
|
35 |
if not api_key:
|
36 |
-
# Display a pop-up info message
|
37 |
gr.Info("API key is missing. Please enter your API key to proceed.")
|
38 |
-
return "", ""
|
39 |
|
40 |
if not client:
|
41 |
-
|
42 |
|
43 |
# Get the evaluator instance by name
|
44 |
evaluator = client.evaluators.get_by_name(name=selected_evaluator)
|
45 |
|
46 |
-
# Run evaluation using selected evaluator
|
47 |
evaluation_result = evaluator.run(request=user_input, response=llm_response)
|
48 |
score = evaluation_result.score
|
49 |
justification = evaluation_result.justification
|
50 |
-
|
|
|
51 |
|
52 |
-
|
53 |
-
# Create the interface with a custom layout
|
54 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
55 |
-
gr.HTML(
|
|
|
56 |
<img src="https://api.visitorbadge.io/api/visitors?path=https://huggingface.co/spaces/root-signals/RootEvaluatorsDemo" />
|
57 |
-
|
|
|
58 |
|
59 |
with gr.Row():
|
60 |
gr.Image(value="https://app.rootsignals.ai/images/root-signals-color.svg", height=70)
|
61 |
-
gr.Markdown("<div> </div>")
|
62 |
gr.Markdown("# *Root* Evaluators Demo by Root Signals")
|
63 |
-
|
64 |
-
|
|
|
|
|
65 |
|
66 |
api_key = gr.Textbox(
|
67 |
label="🔑 Root Signals API Key",
|
@@ -69,21 +71,21 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
|
69 |
type="password",
|
70 |
show_label=True,
|
71 |
)
|
72 |
-
|
73 |
-
gr.Markdown("---")
|
74 |
|
75 |
with gr.Row():
|
76 |
# Left column
|
77 |
with gr.Column():
|
78 |
user_input = gr.Textbox(
|
79 |
-
label="👤 User Instruction or Question (Optional)",
|
80 |
-
placeholder="Enter user input here...",
|
81 |
value="Where can I apply to this position?",
|
82 |
interactive=True
|
83 |
)
|
84 |
llm_response = gr.Textbox(
|
85 |
-
label="🤖 LLM Response (to be evaluated)",
|
86 |
-
placeholder="Enter the LLM response to be evaluated here...",
|
87 |
value="You can find the instructions from our Careers page.",
|
88 |
interactive=True
|
89 |
)
|
@@ -99,19 +101,30 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
|
99 |
score = gr.Textbox(label="📊 Score (between 0 and 1)", interactive=False)
|
100 |
justification = gr.TextArea(label="💬 Justification", interactive=False)
|
101 |
|
102 |
-
# Initialize client
|
103 |
api_key.change(
|
104 |
fn=initialize_client,
|
105 |
inputs=[api_key],
|
106 |
outputs=[]
|
107 |
)
|
108 |
|
109 |
-
# Button to trigger the
|
110 |
submit_btn = gr.Button("🧐 EVALUATE", variant="primary")
|
|
|
|
|
|
|
111 |
submit_btn.click(
|
112 |
fn=process_and_evaluate,
|
113 |
inputs=[api_key, user_input, llm_response, evaluator_dropdown],
|
114 |
-
outputs=[score, justification]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
)
|
116 |
|
117 |
gr.Markdown("[🌐 Homepage](https://www.rootsignals.ai/) | [🤖 Github Repo](https://github.com/root-signals/rs-python-sdk) | [🐍 Python SDK Docs](https://sdk.rootsignals.ai/en/latest/) | [💬 Discord](https://discord.gg/EhazTQsFnj)")
|
|
|
1 |
import gradio as gr
|
2 |
from root import RootSignals
|
3 |
|
4 |
+
client = None
|
5 |
|
6 |
ROOT_EVALUATORS = ['Answer Correctness',
|
7 |
'Answer Relevance',
|
|
|
28 |
def initialize_client(api_key):
|
29 |
global client
|
30 |
client = RootSignals(api_key=api_key)
|
|
|
31 |
|
32 |
def process_and_evaluate(api_key, user_input, llm_response, selected_evaluator):
|
33 |
global client
|
34 |
if not api_key:
|
35 |
+
# Display a pop-up info message (if supported by your version)
|
36 |
gr.Info("API key is missing. Please enter your API key to proceed.")
|
37 |
+
return "", "", gr.update(visible=False)
|
38 |
|
39 |
if not client:
|
40 |
+
initialize_client(api_key)
|
41 |
|
42 |
# Get the evaluator instance by name
|
43 |
evaluator = client.evaluators.get_by_name(name=selected_evaluator)
|
44 |
|
45 |
+
# Run evaluation using the selected evaluator
|
46 |
evaluation_result = evaluator.run(request=user_input, response=llm_response)
|
47 |
score = evaluation_result.score
|
48 |
justification = evaluation_result.justification
|
49 |
+
# Reveal the monitoring button
|
50 |
+
return score, justification, gr.update(visible=True)
|
51 |
|
|
|
|
|
52 |
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
53 |
+
gr.HTML(
|
54 |
+
"""<a href="https://api.visitorbadge.io/api/visitors?path=https://huggingface.co/spaces/root-signals/RootEvaluatorsDemo">
|
55 |
<img src="https://api.visitorbadge.io/api/visitors?path=https://huggingface.co/spaces/root-signals/RootEvaluatorsDemo" />
|
56 |
+
</a>"""
|
57 |
+
)
|
58 |
|
59 |
with gr.Row():
|
60 |
gr.Image(value="https://app.rootsignals.ai/images/root-signals-color.svg", height=70)
|
61 |
+
gr.Markdown("<div> </div>")
|
62 |
gr.Markdown("# *Root* Evaluators Demo by Root Signals")
|
63 |
+
gr.Markdown(
|
64 |
+
"[Sign-up](https://app.rootsignals.ai/register) to create your API key or "
|
65 |
+
"[create a temporary one](https://app.rootsignals.ai/demo-user)!"
|
66 |
+
)
|
67 |
|
68 |
api_key = gr.Textbox(
|
69 |
label="🔑 Root Signals API Key",
|
|
|
71 |
type="password",
|
72 |
show_label=True,
|
73 |
)
|
74 |
+
|
75 |
+
gr.Markdown("---")
|
76 |
|
77 |
with gr.Row():
|
78 |
# Left column
|
79 |
with gr.Column():
|
80 |
user_input = gr.Textbox(
|
81 |
+
label="👤 User Instruction or Question (Optional)",
|
82 |
+
placeholder="Enter user input here...",
|
83 |
value="Where can I apply to this position?",
|
84 |
interactive=True
|
85 |
)
|
86 |
llm_response = gr.Textbox(
|
87 |
+
label="🤖 LLM Response (to be evaluated)",
|
88 |
+
placeholder="Enter the LLM response to be evaluated here...",
|
89 |
value="You can find the instructions from our Careers page.",
|
90 |
interactive=True
|
91 |
)
|
|
|
101 |
score = gr.Textbox(label="📊 Score (between 0 and 1)", interactive=False)
|
102 |
justification = gr.TextArea(label="💬 Justification", interactive=False)
|
103 |
|
104 |
+
# Initialize client when API key is provided.
|
105 |
api_key.change(
|
106 |
fn=initialize_client,
|
107 |
inputs=[api_key],
|
108 |
outputs=[]
|
109 |
)
|
110 |
|
111 |
+
# Button to trigger the evaluation.
|
112 |
submit_btn = gr.Button("🧐 EVALUATE", variant="primary")
|
113 |
+
# New button for monitoring (initially hidden).
|
114 |
+
monitoring_btn = gr.Button("See in Root Signals Monitoring View", visible=False)
|
115 |
+
|
116 |
submit_btn.click(
|
117 |
fn=process_and_evaluate,
|
118 |
inputs=[api_key, user_input, llm_response, evaluator_dropdown],
|
119 |
+
outputs=[score, justification, monitoring_btn]
|
120 |
+
)
|
121 |
+
|
122 |
+
# When clicked, the monitoring button opens the monitoring dashboard.
|
123 |
+
monitoring_btn.click(
|
124 |
+
fn=None,
|
125 |
+
inputs=[],
|
126 |
+
outputs=[],
|
127 |
+
js="() => window.open('https://app.rootsignals.ai/monitoring/dashboard', '_blank')"
|
128 |
)
|
129 |
|
130 |
gr.Markdown("[🌐 Homepage](https://www.rootsignals.ai/) | [🤖 Github Repo](https://github.com/root-signals/rs-python-sdk) | [🐍 Python SDK Docs](https://sdk.rootsignals.ai/en/latest/) | [💬 Discord](https://discord.gg/EhazTQsFnj)")
|