Spaces:
Running
on
Zero
Running
on
Zero
Martín Santillán Cooper
commited on
Commit
•
d892a20
1
Parent(s):
fb70e60
look & feel improvements
Browse files- app.py +25 -18
- styles.css +17 -1
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
from dotenv import load_dotenv
|
3 |
import json
|
4 |
from generate import generate_text, get_prompt_from_test_case
|
5 |
-
|
6 |
# load_dotenv()
|
7 |
|
8 |
catalog = {}
|
@@ -18,6 +18,8 @@ context = gr.Textbox(label="Context", lines=3, interactive=True, value=starting_
|
|
18 |
user_message = gr.Textbox(label="User Message", lines=3, interactive=True, value=starting_test_case['user_message'])
|
19 |
assistant_message = gr.Textbox(label="Assistant Message", lines=3, interactive=True, value=starting_test_case['assistant_message'])
|
20 |
catalog_buttons: dict[str,dict[str,gr.Button]] = {}
|
|
|
|
|
21 |
|
22 |
for sub_catalog_name, sub_catalog in catalog.items():
|
23 |
catalog_buttons[sub_catalog_name] = {}
|
@@ -55,54 +57,59 @@ def on_test_case_click(link):
|
|
55 |
context: selected_test_case['context'] if selected_test_case['context'] is not None else gr.update(visible=False),
|
56 |
user_message: selected_test_case['user_message'],
|
57 |
assistant_message: selected_test_case['assistant_message'],
|
|
|
|
|
58 |
}
|
59 |
|
60 |
def change_button_color(event: gr.EventData):
|
61 |
return [gr.update(elem_classes=['catalog-button', 'selected']) if v.elem_id == event.target.elem_id else gr.update(elem_classes=['catalog-button']) for c in catalog_buttons.values() for v in c.values()]
|
62 |
|
63 |
def on_submit(inputs):
|
64 |
-
prompt = get_prompt_from_test_case({
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
})
|
70 |
-
result = generate_text(prompt)
|
71 |
-
return result['assessment'], result['certainty']
|
|
|
|
|
72 |
|
73 |
with gr.Blocks(
|
74 |
theme=gr.themes.Soft(font=[gr.themes.GoogleFont("IBM Plex Sans")]), css='styles.css') as demo:
|
75 |
with gr.Row():
|
76 |
gr.HTML('<h1>Granite Guardian</h1>', elem_classes='title')
|
77 |
-
with gr.Row():
|
78 |
with gr.Column(scale=0):
|
79 |
title_display_left = gr.HTML("<h2>Catalog - Harms & Risks</h2>")
|
80 |
accordions = []
|
81 |
-
for sub_catalog_name, sub_catalog in catalog.items():
|
82 |
-
with gr.Accordion(sub_catalog_name, open=
|
83 |
for test_case in sub_catalog:
|
84 |
link = catalog_buttons[sub_catalog_name][test_case['name']]
|
85 |
link.render()
|
86 |
-
link.click(on_test_case_click, link, {test_case_name, criteria, context, user_message, assistant_message}) \
|
87 |
.then(change_button_color, None, [v for c in catalog_buttons.values() for v in c.values()])
|
88 |
accordions.append(accordion)
|
89 |
def on_accordion_open(open):
|
90 |
pass
|
91 |
with gr.Column(visible=True) as test_case_content:
|
92 |
test_case_name.render()
|
93 |
-
gr.HTML("Evaluation Criteria")
|
94 |
criteria.render()
|
95 |
|
96 |
-
gr.
|
97 |
context.render()
|
98 |
user_message.render()
|
99 |
assistant_message.render()
|
100 |
|
101 |
submit_button = gr.Button("Evaluate", variant='primary')
|
|
|
102 |
with gr.Row():
|
103 |
-
result_text
|
104 |
-
result_certainty
|
105 |
-
|
106 |
submit_button.click(
|
107 |
on_submit,
|
108 |
inputs={test_case_name, criteria, context, user_message, assistant_message},
|
|
|
2 |
from dotenv import load_dotenv
|
3 |
import json
|
4 |
from generate import generate_text, get_prompt_from_test_case
|
5 |
+
from time import sleep
|
6 |
# load_dotenv()
|
7 |
|
8 |
catalog = {}
|
|
|
18 |
user_message = gr.Textbox(label="User Message", lines=3, interactive=True, value=starting_test_case['user_message'])
|
19 |
assistant_message = gr.Textbox(label="Assistant Message", lines=3, interactive=True, value=starting_test_case['assistant_message'])
|
20 |
catalog_buttons: dict[str,dict[str,gr.Button]] = {}
|
21 |
+
result_text = gr.Textbox(label="Result", interactive=False)
|
22 |
+
result_certainty = gr.Number(label="Certainty", interactive=False, value='')
|
23 |
|
24 |
for sub_catalog_name, sub_catalog in catalog.items():
|
25 |
catalog_buttons[sub_catalog_name] = {}
|
|
|
57 |
context: selected_test_case['context'] if selected_test_case['context'] is not None else gr.update(visible=False),
|
58 |
user_message: selected_test_case['user_message'],
|
59 |
assistant_message: selected_test_case['assistant_message'],
|
60 |
+
result_text: gr.update(value=''),
|
61 |
+
result_certainty: gr.update(value='')
|
62 |
}
|
63 |
|
64 |
def change_button_color(event: gr.EventData):
|
65 |
return [gr.update(elem_classes=['catalog-button', 'selected']) if v.elem_id == event.target.elem_id else gr.update(elem_classes=['catalog-button']) for c in catalog_buttons.values() for v in c.values()]
|
66 |
|
67 |
def on_submit(inputs):
|
68 |
+
# prompt = get_prompt_from_test_case({
|
69 |
+
# 'criteria': inputs[criteria],
|
70 |
+
# 'context': inputs[context],
|
71 |
+
# 'user_message': inputs[user_message],
|
72 |
+
# 'assistant_message': inputs[assistant_message],
|
73 |
+
# })
|
74 |
+
# result = generate_text(prompt)
|
75 |
+
# return result['assessment'], result['certainty']
|
76 |
+
sleep(3)
|
77 |
+
return 'Yes', 0.97
|
78 |
|
79 |
with gr.Blocks(
|
80 |
theme=gr.themes.Soft(font=[gr.themes.GoogleFont("IBM Plex Sans")]), css='styles.css') as demo:
|
81 |
with gr.Row():
|
82 |
gr.HTML('<h1>Granite Guardian</h1>', elem_classes='title')
|
83 |
+
with gr.Row(elem_classes='column-gap'):
|
84 |
with gr.Column(scale=0):
|
85 |
title_display_left = gr.HTML("<h2>Catalog - Harms & Risks</h2>")
|
86 |
accordions = []
|
87 |
+
for i, (sub_catalog_name, sub_catalog) in enumerate(catalog.items()):
|
88 |
+
with gr.Accordion(sub_catalog_name, open=i==0, elem_classes='accordion-align') as accordion:
|
89 |
for test_case in sub_catalog:
|
90 |
link = catalog_buttons[sub_catalog_name][test_case['name']]
|
91 |
link.render()
|
92 |
+
link.click(on_test_case_click, link, {test_case_name, criteria, context, user_message, assistant_message, result_text, result_certainty}) \
|
93 |
.then(change_button_color, None, [v for c in catalog_buttons.values() for v in c.values()])
|
94 |
accordions.append(accordion)
|
95 |
def on_accordion_open(open):
|
96 |
pass
|
97 |
with gr.Column(visible=True) as test_case_content:
|
98 |
test_case_name.render()
|
99 |
+
gr.HTML("Evaluation Criteria", elem_classes='subtitle')
|
100 |
criteria.render()
|
101 |
|
102 |
+
gr.HTML("Test Data", elem_classes='subtitle')
|
103 |
context.render()
|
104 |
user_message.render()
|
105 |
assistant_message.render()
|
106 |
|
107 |
submit_button = gr.Button("Evaluate", variant='primary')
|
108 |
+
gr.HTML("Evaluation results", elem_classes='subtitle')
|
109 |
with gr.Row():
|
110 |
+
result_text.render()
|
111 |
+
result_certainty.render()
|
112 |
+
|
113 |
submit_button.click(
|
114 |
on_submit,
|
115 |
inputs={test_case_name, criteria, context, user_message, assistant_message},
|
styles.css
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
.title {
|
2 |
-
margin-
|
|
|
3 |
}
|
4 |
|
5 |
.title h1 {
|
6 |
font-weight: 100 !important;
|
7 |
}
|
8 |
|
|
|
|
|
|
|
|
|
9 |
.catalog-button {
|
10 |
/* // align left
|
11 |
smaller font, lighter
|
@@ -15,6 +20,7 @@
|
|
15 |
justify-content: flex-start;
|
16 |
background-color: transparent;
|
17 |
box-shadow: none;
|
|
|
18 |
}
|
19 |
|
20 |
.selected {
|
@@ -24,3 +30,13 @@
|
|
24 |
.sidebar {
|
25 |
margin-right: 4rem;
|
26 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
.title {
|
2 |
+
margin-top: 0.5rem;
|
3 |
+
margin-bottom: 0rem;
|
4 |
}
|
5 |
|
6 |
.title h1 {
|
7 |
font-weight: 100 !important;
|
8 |
}
|
9 |
|
10 |
+
.subtitle {
|
11 |
+
margin-bottom: -5px;
|
12 |
+
}
|
13 |
+
|
14 |
.catalog-button {
|
15 |
/* // align left
|
16 |
smaller font, lighter
|
|
|
20 |
justify-content: flex-start;
|
21 |
background-color: transparent;
|
22 |
box-shadow: none;
|
23 |
+
|
24 |
}
|
25 |
|
26 |
.selected {
|
|
|
30 |
.sidebar {
|
31 |
margin-right: 4rem;
|
32 |
}
|
33 |
+
|
34 |
+
.column-gap {
|
35 |
+
gap: 2rem
|
36 |
+
}
|
37 |
+
|
38 |
+
.accordion-align span {
|
39 |
+
display: block;
|
40 |
+
text-align: left;
|
41 |
+
font-weight: 600 !important;
|
42 |
+
}
|