Spaces:
Running
Running
Ouz
commited on
Commit
·
37f0854
1
Parent(s):
385be56
first version
Browse files- app.py +91 -4
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,7 +1,94 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from root import RootSignals, skills
|
3 |
|
4 |
+
client = None # Initialize client as None
|
|
|
5 |
|
6 |
+
ROOT_EVALUATORS = ['Answer Correctness',
|
7 |
+
'Answer Relevance',
|
8 |
+
'Clarity',
|
9 |
+
'Coherence',
|
10 |
+
'Conciseness',
|
11 |
+
'Confidentiality',
|
12 |
+
'Engagingness',
|
13 |
+
'Formality',
|
14 |
+
'Harmlessness',
|
15 |
+
'Helpfulness',
|
16 |
+
'Non-toxicity',
|
17 |
+
'Originality',
|
18 |
+
'Persuasiveness',
|
19 |
+
'Politeness',
|
20 |
+
'Precision',
|
21 |
+
'Quality of Writing Creative',
|
22 |
+
'Quality of Writing Professional',
|
23 |
+
'Relevance',
|
24 |
+
'Safety for Children',
|
25 |
+
'Sentiment recognition',
|
26 |
+
]
|
27 |
+
|
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 client:
|
36 |
+
evaluator_dropdown = initialize_client(api_key)
|
37 |
+
|
38 |
+
# Get the evaluator instance by name
|
39 |
+
evaluator = client.evaluators.get_by_name(name=selected_evaluator)
|
40 |
+
|
41 |
+
# Run evaluation using selected evaluator
|
42 |
+
evaluation_result = evaluator.run(request=user_input, response=llm_response)
|
43 |
+
score = evaluation_result.score
|
44 |
+
justification = evaluation_result.justification
|
45 |
+
return score, justification
|
46 |
+
|
47 |
+
|
48 |
+
# Create the interface with a custom layout
|
49 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
50 |
+
with gr.Row():
|
51 |
+
gr.Image(value="https://lh3.googleusercontent.com/d/1e49skZjYGTZscWCVrhf6Ad1bRP2pvwpI", height=60)
|
52 |
+
gr.Markdown("<div> </div>") # Add some space below the image
|
53 |
+
gr.Markdown("# Root Evaluators Demo by Root Signals")
|
54 |
+
|
55 |
+
api_key = gr.Textbox(
|
56 |
+
label="🔑 Root Signals API Key",
|
57 |
+
placeholder="Enter your Root Signals API key...",
|
58 |
+
type="password",
|
59 |
+
show_label=True,
|
60 |
+
)
|
61 |
+
|
62 |
+
with gr.Row():
|
63 |
+
# Left column
|
64 |
+
with gr.Column():
|
65 |
+
user_input = gr.Textbox(label="👤 User Instruction or Question (Optional)", placeholder="Enter user input here...", interactive=True)
|
66 |
+
llm_response = gr.Textbox(label="🤖 LLM Response (to be evaluated)", placeholder="Enter the LLM response to be evaluated here...", interactive=True)
|
67 |
+
evaluator_dropdown = gr.Dropdown(
|
68 |
+
label="🔎 Select Evaluator",
|
69 |
+
choices=[], # Will be populated after client initialization
|
70 |
+
interactive=True
|
71 |
+
)
|
72 |
+
|
73 |
+
# Right column
|
74 |
+
with gr.Column():
|
75 |
+
score = gr.Textbox(label="📊 Score (between 0 and 1)", interactive=False)
|
76 |
+
justification = gr.TextArea(label="💬 Justification", interactive=False)
|
77 |
+
|
78 |
+
# Initialize client and update dropdown when API key is provided
|
79 |
+
api_key.change(
|
80 |
+
fn=initialize_client,
|
81 |
+
inputs=[api_key],
|
82 |
+
outputs=[evaluator_dropdown]
|
83 |
+
)
|
84 |
+
|
85 |
+
# Button to trigger the process
|
86 |
+
submit_btn = gr.Button("🧐 EVALUATE", variant="primary")
|
87 |
+
submit_btn.click(
|
88 |
+
fn=process_and_evaluate,
|
89 |
+
inputs=[api_key, user_input, llm_response, evaluator_dropdown],
|
90 |
+
outputs=[score, justification]
|
91 |
+
)
|
92 |
+
|
93 |
+
if __name__ == "__main__":
|
94 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio==5.13.2
|
2 |
+
root-signals==1.3.3
|