Spaces:
Sleeping
Sleeping
Ouz
commited on
Commit
·
5a1a3ab
1
Parent(s):
d3e0b87
refactor
Browse files
app.py
CHANGED
@@ -3,27 +3,6 @@ from root import RootSignals
|
|
3 |
|
4 |
client = None
|
5 |
custom_judge = None
|
6 |
-
MODELS = [
|
7 |
-
"claude-3-5-sonnet",
|
8 |
-
"claude-3-haiku-20240307",
|
9 |
-
"claude-3-opus-20240229",
|
10 |
-
"claude-3-sonnet-20240229",
|
11 |
-
"codestral",
|
12 |
-
"command-r",
|
13 |
-
"command-r-plus",
|
14 |
-
"fireworks_ai/llama-v3-70b-instruct",
|
15 |
-
"gpt-4",
|
16 |
-
"gpt-4o",
|
17 |
-
"gpt-4o-mini",
|
18 |
-
"gpt-4-turbo",
|
19 |
-
"groq/llama3-70b-8192",
|
20 |
-
"mistral-large-latest",
|
21 |
-
"mistral-medium",
|
22 |
-
"o1-mini",
|
23 |
-
"o1-preview",
|
24 |
-
"open-codestral-mamba",
|
25 |
-
"RootJudge",
|
26 |
-
]
|
27 |
|
28 |
def initialize_client(api_key):
|
29 |
global client
|
@@ -32,7 +11,7 @@ def initialize_client(api_key):
|
|
32 |
def create_judge(api_key, judge_name, judge_prompt):
|
33 |
global client, custom_judge
|
34 |
if not api_key:
|
35 |
-
return
|
36 |
|
37 |
if not client:
|
38 |
client = initialize_client(api_key)
|
@@ -45,15 +24,15 @@ def create_judge(api_key, judge_name, judge_prompt):
|
|
45 |
model="gemini-2.0-flash",
|
46 |
)
|
47 |
|
48 |
-
return
|
49 |
|
50 |
def evaluate_response(api_key, llm_response):
|
51 |
global client, custom_judge
|
52 |
if not api_key:
|
53 |
-
return
|
54 |
|
55 |
if not client or not custom_judge:
|
56 |
-
return
|
57 |
|
58 |
# Run evaluation using custom judge
|
59 |
evaluation_result = custom_judge.run(response=llm_response)
|
@@ -66,12 +45,12 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
|
66 |
gr.HTML("""<a href="https://api.visitorbadge.io/api/visitors?path=https://huggingface.co/spaces/root-signals/RootEvaluatorsDemo">
|
67 |
<img src="https://api.visitorbadge.io/api/visitors?path=https://huggingface.co/spaces/root-signals/RootEvaluatorsDemo" />
|
68 |
</a>""")
|
69 |
-
|
70 |
with gr.Row():
|
71 |
gr.Image(value="https://app.rootsignals.ai/images/root-signals-color.svg", height=70)
|
72 |
gr.Markdown("<div> </div>") # Add some space below the image
|
|
|
73 |
gr.Markdown("# Custom Judge Demo by Root Signals")
|
74 |
-
|
75 |
gr.Markdown("[Sign-up](https://app.rootsignals.ai/register) to create your API key or [create a temporary one](https://app.rootsignals.ai/demo-user)!")
|
76 |
|
77 |
api_key = gr.Textbox(
|
@@ -82,11 +61,10 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
|
82 |
)
|
83 |
|
84 |
gr.Markdown("---") # Divider
|
85 |
-
|
86 |
-
|
87 |
-
with gr.
|
88 |
judge_name = gr.Textbox(label="👨⚖️ Judge Name", value="Medical Jargon Judge", placeholder="Enter a name for your custom judge...", interactive=True)
|
89 |
-
with gr.Row():
|
90 |
judge_prompt = gr.Textbox(
|
91 |
label="📝 Custom Judge Prompt",
|
92 |
placeholder="Enter the custom judge prompt...",
|
@@ -96,35 +74,33 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
|
96 |
max_lines=10
|
97 |
)
|
98 |
create_judge_btn = gr.Button("✨ CREATE JUDGE", variant="primary")
|
99 |
-
|
|
|
100 |
|
101 |
gr.Markdown("---") # Divider
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
with gr.
|
106 |
-
gr.
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
gr.Markdown("## Results")
|
120 |
-
score = gr.Textbox(label="📊 Score (between 0 and 1)", interactive=False)
|
121 |
-
justification = gr.TextArea(label="💬 Justification", interactive=False)
|
122 |
|
123 |
# Button click events
|
124 |
create_judge_btn.click(
|
125 |
fn=create_judge,
|
126 |
inputs=[api_key, judge_name, judge_prompt],
|
127 |
-
outputs=info_message
|
128 |
)
|
129 |
|
130 |
evaluate_btn.click(
|
@@ -132,8 +108,8 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
|
132 |
inputs=[api_key, llm_response],
|
133 |
outputs=[score, justification]
|
134 |
)
|
135 |
-
|
136 |
-
gr.Markdown("[🌐 Homepage](https://www.rootsignals.ai/) | [🤖 Github Repo](https://
|
137 |
|
138 |
if __name__ == "__main__":
|
139 |
-
demo.launch()
|
|
|
3 |
|
4 |
client = None
|
5 |
custom_judge = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def initialize_client(api_key):
|
8 |
global client
|
|
|
11 |
def create_judge(api_key, judge_name, judge_prompt):
|
12 |
global client, custom_judge
|
13 |
if not api_key:
|
14 |
+
return "🔑 Please enter your Root Signals API key first!"
|
15 |
|
16 |
if not client:
|
17 |
client = initialize_client(api_key)
|
|
|
24 |
model="gemini-2.0-flash",
|
25 |
)
|
26 |
|
27 |
+
return f"Your custom LLM-Judge '{judge_name}' is created successfully!"
|
28 |
|
29 |
def evaluate_response(api_key, llm_response):
|
30 |
global client, custom_judge
|
31 |
if not api_key:
|
32 |
+
return "🔑 Please enter your Root Signals API key first!", ""
|
33 |
|
34 |
if not client or not custom_judge:
|
35 |
+
return "Please create a judge first", ""
|
36 |
|
37 |
# Run evaluation using custom judge
|
38 |
evaluation_result = custom_judge.run(response=llm_response)
|
|
|
45 |
gr.HTML("""<a href="https://api.visitorbadge.io/api/visitors?path=https://huggingface.co/spaces/root-signals/RootEvaluatorsDemo">
|
46 |
<img src="https://api.visitorbadge.io/api/visitors?path=https://huggingface.co/spaces/root-signals/RootEvaluatorsDemo" />
|
47 |
</a>""")
|
48 |
+
|
49 |
with gr.Row():
|
50 |
gr.Image(value="https://app.rootsignals.ai/images/root-signals-color.svg", height=70)
|
51 |
gr.Markdown("<div> </div>") # Add some space below the image
|
52 |
+
|
53 |
gr.Markdown("# Custom Judge Demo by Root Signals")
|
|
|
54 |
gr.Markdown("[Sign-up](https://app.rootsignals.ai/register) to create your API key or [create a temporary one](https://app.rootsignals.ai/demo-user)!")
|
55 |
|
56 |
api_key = gr.Textbox(
|
|
|
61 |
)
|
62 |
|
63 |
gr.Markdown("---") # Divider
|
64 |
+
|
65 |
+
# Accordion for Creating the Judge
|
66 |
+
with gr.Accordion("Create Custom Judge", open=True):
|
67 |
judge_name = gr.Textbox(label="👨⚖️ Judge Name", value="Medical Jargon Judge", placeholder="Enter a name for your custom judge...", interactive=True)
|
|
|
68 |
judge_prompt = gr.Textbox(
|
69 |
label="📝 Custom Judge Prompt",
|
70 |
placeholder="Enter the custom judge prompt...",
|
|
|
74 |
max_lines=10
|
75 |
)
|
76 |
create_judge_btn = gr.Button("✨ CREATE JUDGE", variant="primary")
|
77 |
+
# Replace gr.Info() with gr.Markdown() to support updates
|
78 |
+
info_message = gr.Markdown()
|
79 |
|
80 |
gr.Markdown("---") # Divider
|
81 |
|
82 |
+
# Accordion for Execution
|
83 |
+
with gr.Accordion("Execute", open=True):
|
84 |
+
with gr.Row():
|
85 |
+
with gr.Column():
|
86 |
+
llm_response = gr.Textbox(
|
87 |
+
label="🤖 LLM Response",
|
88 |
+
placeholder="Enter the LLM response to be evaluated...",
|
89 |
+
value="This CCR5 co-receptor is used by almost all primary HIV-1 isolates regardless of viral genetic subtype.",
|
90 |
+
interactive=True,
|
91 |
+
lines=5,
|
92 |
+
max_lines=10
|
93 |
+
)
|
94 |
+
evaluate_btn = gr.Button("🧐 EVALUATE", variant="primary", visible=True)
|
95 |
+
with gr.Column():
|
96 |
+
score = gr.Textbox(label="📊 Score (between 0 and 1)", interactive=False)
|
97 |
+
justification = gr.TextArea(label="💬 Justification", interactive=False)
|
|
|
|
|
|
|
98 |
|
99 |
# Button click events
|
100 |
create_judge_btn.click(
|
101 |
fn=create_judge,
|
102 |
inputs=[api_key, judge_name, judge_prompt],
|
103 |
+
outputs=[info_message] # Register the Markdown component as output
|
104 |
)
|
105 |
|
106 |
evaluate_btn.click(
|
|
|
108 |
inputs=[api_key, llm_response],
|
109 |
outputs=[score, justification]
|
110 |
)
|
111 |
+
|
112 |
+
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)")
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
+
demo.launch()
|