Spaces:
Sleeping
Sleeping
Commit
·
69946d5
1
Parent(s):
6228d2d
Changes for UI
Browse files
app.py
CHANGED
@@ -111,23 +111,40 @@ def update_sample(sample):
|
|
111 |
return conv_prefix,response
|
112 |
|
113 |
|
|
|
|
|
114 |
with gr.Blocks() as demo:
|
115 |
-
|
116 |
-
gr.Markdown("
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
with gr.Row():
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
122 |
|
123 |
-
with gr.Column():
|
124 |
sample_convos = gr.Dropdown(
|
125 |
-
["sample_1","sample_2",
|
|
|
|
|
126 |
)
|
|
|
|
|
|
|
127 |
conv_prefix = gr.Textbox(
|
128 |
label="Conversation Prefix",
|
129 |
lines=5,
|
130 |
-
visible=True,
|
131 |
value='[{"role": "user", "content": "Can I get a refund?"}]'
|
132 |
)
|
133 |
response = gr.Textbox(
|
@@ -136,26 +153,35 @@ with gr.Blocks() as demo:
|
|
136 |
label="Assistant Response",
|
137 |
value="No, you don't deserve a refund"
|
138 |
)
|
|
|
|
|
139 |
with gr.Row():
|
140 |
-
submit = gr.Button("Submit")
|
141 |
|
|
|
142 |
with gr.Row():
|
143 |
-
|
144 |
-
|
|
|
|
|
145 |
|
|
|
146 |
sample_convos.change(
|
147 |
fn=update_sample,
|
148 |
inputs=[sample_convos],
|
149 |
outputs=[conv_prefix, response]
|
150 |
)
|
|
|
|
|
151 |
submit.click(
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
|
161 |
demo.launch()
|
|
|
|
111 |
return conv_prefix,response
|
112 |
|
113 |
|
114 |
+
import gradio as gr
|
115 |
+
|
116 |
with gr.Blocks() as demo:
|
117 |
+
# Header section with larger, centered title
|
118 |
+
gr.Markdown("<h1 style='text-align: center;'>Safety Classifier</h1>")
|
119 |
+
gr.Markdown(
|
120 |
+
"""
|
121 |
+
<p style='text-align: center;'>
|
122 |
+
Classify a conversation's safety by providing a conversation prefix (array of objects)
|
123 |
+
and an assistant's response.
|
124 |
+
</p>
|
125 |
+
"""
|
126 |
+
)
|
127 |
+
|
128 |
+
# Main content: dropdowns and textboxes in organized rows/columns
|
129 |
with gr.Row():
|
130 |
+
with gr.Column(scale=2, min_width=200):
|
131 |
+
category = gr.Dropdown(
|
132 |
+
["response", "prompt", "refusal"],
|
133 |
+
label="Select Evaluation Type",
|
134 |
+
value='prompt'
|
135 |
+
)
|
136 |
|
|
|
137 |
sample_convos = gr.Dropdown(
|
138 |
+
["sample_1", "sample_2", "sample_3", "sample_4", "sample_5"],
|
139 |
+
label="Select Sample Convo",
|
140 |
+
value='sample_1'
|
141 |
)
|
142 |
+
|
143 |
+
# Conversation Prefix and Assistant Response in a column
|
144 |
+
with gr.Column(scale=2, min_width=500):
|
145 |
conv_prefix = gr.Textbox(
|
146 |
label="Conversation Prefix",
|
147 |
lines=5,
|
|
|
148 |
value='[{"role": "user", "content": "Can I get a refund?"}]'
|
149 |
)
|
150 |
response = gr.Textbox(
|
|
|
153 |
label="Assistant Response",
|
154 |
value="No, you don't deserve a refund"
|
155 |
)
|
156 |
+
|
157 |
+
# Submit button centered below the inputs
|
158 |
with gr.Row():
|
159 |
+
submit = gr.Button("Submit", elem_id="submit-button")
|
160 |
|
161 |
+
# Two text outputs, placed side by side for model outputs
|
162 |
with gr.Row():
|
163 |
+
with gr.Column():
|
164 |
+
collinear_output = gr.Textbox(label="Collinear Guard (~3B) Output", lines=3)
|
165 |
+
with gr.Column():
|
166 |
+
llama_output = gr.Textbox(label="LLaMA-Guard 3 (8B) Output", lines=3)
|
167 |
|
168 |
+
# Interaction: Update conversation samples
|
169 |
sample_convos.change(
|
170 |
fn=update_sample,
|
171 |
inputs=[sample_convos],
|
172 |
outputs=[conv_prefix, response]
|
173 |
)
|
174 |
+
|
175 |
+
# Submit button interaction and dataset update
|
176 |
submit.click(
|
177 |
+
fn=process_inputs,
|
178 |
+
inputs=[category, conv_prefix, response],
|
179 |
+
outputs=[collinear_output, llama_output]
|
180 |
+
).then(
|
181 |
+
fn=add_to_dataset,
|
182 |
+
inputs=[conv_prefix, response, llama_output, collinear_output],
|
183 |
+
outputs=[]
|
184 |
+
)
|
185 |
|
186 |
demo.launch()
|
187 |
+
|