Spaces:
Sleeping
Sleeping
Added close button.
Browse files- app/gradio_sample_generator.py +131 -87
app/gradio_sample_generator.py
CHANGED
@@ -5,17 +5,17 @@ import pandas as pd
|
|
5 |
from langchain_openai import ChatOpenAI
|
6 |
from meta_prompt.sample_generator import TaskDescriptionGenerator
|
7 |
|
8 |
-
def
|
9 |
pd_examples = pd.DataFrame(examples)
|
10 |
pd_examples.columns = pd_examples.columns.str.lower()
|
11 |
return pd_examples.to_json(orient="records")
|
12 |
|
13 |
-
def
|
14 |
examples, model_name, generating_batch_size, temperature
|
15 |
):
|
16 |
try:
|
17 |
# Convert the gradio dataframe into a JSON array
|
18 |
-
input_json =
|
19 |
|
20 |
model = ChatOpenAI(
|
21 |
model=model_name, temperature=temperature, max_retries=3
|
@@ -50,9 +50,9 @@ def process_json(
|
|
50 |
except Exception as e:
|
51 |
raise gr.Error(f"An error occurred: {str(e)}")
|
52 |
|
53 |
-
def
|
54 |
try:
|
55 |
-
input_json =
|
56 |
|
57 |
model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
|
58 |
generator = TaskDescriptionGenerator(model)
|
@@ -61,7 +61,7 @@ def generate_description_only(examples, model_name, temperature):
|
|
61 |
except Exception as e:
|
62 |
raise gr.Error(f"An error occurred: {str(e)}")
|
63 |
|
64 |
-
def
|
65 |
try:
|
66 |
model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
|
67 |
generator = TaskDescriptionGenerator(model)
|
@@ -70,7 +70,7 @@ def analyze_input(description, model_name, temperature):
|
|
70 |
except Exception as e:
|
71 |
raise gr.Error(f"An error occurred: {str(e)}")
|
72 |
|
73 |
-
def
|
74 |
description, input_analysis, generating_batch_size, model_name, temperature
|
75 |
):
|
76 |
try:
|
@@ -86,11 +86,11 @@ def generate_briefs(
|
|
86 |
raise gr.Error(f"An error occurred: {str(e)}")
|
87 |
|
88 |
|
89 |
-
def
|
90 |
description, new_example_briefs, examples, generating_batch_size, model_name, temperature
|
91 |
):
|
92 |
try:
|
93 |
-
input_json =
|
94 |
model = ChatOpenAI(
|
95 |
model=model_name, temperature=temperature, max_retries=3
|
96 |
)
|
@@ -107,11 +107,11 @@ def generate_examples_from_briefs(
|
|
107 |
raise gr.Error(f"An error occurred: {str(e)}")
|
108 |
|
109 |
|
110 |
-
def
|
111 |
description, raw_example, generating_batch_size, model_name, temperature
|
112 |
):
|
113 |
try:
|
114 |
-
input_json =
|
115 |
model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
|
116 |
generator = TaskDescriptionGenerator(model)
|
117 |
result = generator.generate_examples_directly(
|
@@ -125,39 +125,47 @@ def generate_examples_directly(
|
|
125 |
raise gr.Error(f"An error occurred: {str(e)}")
|
126 |
|
127 |
|
128 |
-
def
|
129 |
if evt.index[0] < len(examples):
|
130 |
selected_example = examples.iloc[evt.index[0]]
|
131 |
return (
|
132 |
selected_example.iloc[0],
|
133 |
selected_example.iloc[1],
|
134 |
evt.index[0] + 1,
|
135 |
-
gr.update(
|
|
|
|
|
|
|
|
|
136 |
)
|
137 |
-
return "", "", None, gr.update(
|
138 |
|
139 |
-
def
|
140 |
if evt.index[0] < len(examples):
|
141 |
selected_example = examples.iloc[evt.index[0]]
|
142 |
return (
|
143 |
selected_example.iloc[0],
|
144 |
selected_example.iloc[1],
|
145 |
-
gr.update(
|
|
|
|
|
|
|
|
|
146 |
)
|
147 |
-
return "", "", gr.update(
|
148 |
|
149 |
-
def
|
150 |
if file is not None:
|
151 |
df = pd.read_json(file.name)
|
152 |
# Uppercase the first letter of each column name
|
153 |
df.columns = df.columns.str.title()
|
154 |
return df
|
155 |
-
return
|
156 |
|
157 |
-
def
|
158 |
-
if
|
159 |
# Copy the dataframe and lowercase the column names
|
160 |
-
df_copy =
|
161 |
df_copy.columns = df_copy.columns.str.lower()
|
162 |
|
163 |
json_str = df_copy.to_json(orient="records", indent=2)
|
@@ -170,20 +178,32 @@ def export_json(df):
|
|
170 |
return temp_file_path
|
171 |
return None
|
172 |
|
173 |
-
def
|
174 |
try:
|
175 |
new_row = pd.DataFrame([[new_example_input, new_example_output]], columns=['Input', 'Output'])
|
176 |
-
updated_df = pd.concat([
|
177 |
-
return updated_df
|
178 |
except KeyError:
|
179 |
raise gr.Error("Invalid input or output")
|
180 |
|
181 |
-
def
|
182 |
if row_index is not None and row_index > 0:
|
183 |
# Subtract 1 from row_index because it's 1-indexed for display
|
184 |
-
|
185 |
-
return
|
186 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
|
188 |
with gr.Blocks(title="Task Description Generator") as demo:
|
189 |
gr.Markdown("# Task Description Generator")
|
@@ -192,25 +212,31 @@ with gr.Blocks(title="Task Description Generator") as demo:
|
|
192 |
)
|
193 |
|
194 |
|
195 |
-
|
|
|
196 |
label="Input Examples",
|
197 |
headers=["Input", "Output"],
|
198 |
datatype=["str", "str"],
|
199 |
row_count=(1, "dynamic"),
|
200 |
col_count=(2, "fixed"),
|
|
|
201 |
)
|
202 |
-
with gr.Group():
|
|
|
|
|
|
|
203 |
with gr.Row():
|
204 |
selected_example_input = gr.Textbox(label="Selected Example Input", lines=2, show_copy_button=True)
|
205 |
selected_example_output = gr.Textbox(label="Selected Example Output", lines=2, show_copy_button=True)
|
206 |
with gr.Row():
|
207 |
-
|
208 |
-
|
209 |
-
|
|
|
210 |
with gr.Row():
|
211 |
submit_button = gr.Button("Generate", variant="primary")
|
212 |
with gr.Accordion("Import/Export JSON", open=False):
|
213 |
-
|
214 |
label="Import/Export JSON", file_types=[".json"], type="filepath"
|
215 |
)
|
216 |
export_button = gr.Button("Export to JSON")
|
@@ -248,7 +274,7 @@ with gr.Blocks(title="Task Description Generator") as demo:
|
|
248 |
analyze_input_button = gr.Button(
|
249 |
"Analyze Input", variant="secondary"
|
250 |
)
|
251 |
-
|
252 |
label="Examples Directly",
|
253 |
headers=["Input", "Output"],
|
254 |
interactive=False,
|
@@ -268,7 +294,7 @@ with gr.Blocks(title="Task Description Generator") as demo:
|
|
268 |
generate_examples_from_briefs_button = gr.Button(
|
269 |
"Generate Examples from Briefs", variant="secondary"
|
270 |
)
|
271 |
-
|
272 |
label="Examples from Briefs",
|
273 |
headers=["Input", "Output"],
|
274 |
interactive=False,
|
@@ -276,7 +302,7 @@ with gr.Blocks(title="Task Description Generator") as demo:
|
|
276 |
row_count=(1, "dynamic"),
|
277 |
col_count=(2, "fixed"),
|
278 |
)
|
279 |
-
|
280 |
label="Examples",
|
281 |
headers=["Input", "Output"],
|
282 |
interactive=False,
|
@@ -287,74 +313,74 @@ with gr.Blocks(title="Task Description Generator") as demo:
|
|
287 |
|
288 |
clear_button = gr.ClearButton(
|
289 |
[
|
290 |
-
|
291 |
description_output,
|
292 |
input_analysis_output,
|
293 |
example_briefs_output,
|
294 |
-
|
295 |
-
|
296 |
selected_example_input,
|
297 |
selected_example_output,
|
298 |
],
|
299 |
value="Clear All"
|
300 |
)
|
301 |
|
302 |
-
|
303 |
-
fn=
|
304 |
-
inputs=[
|
305 |
-
outputs=[
|
306 |
)
|
307 |
|
308 |
export_button.click(
|
309 |
-
fn=
|
310 |
-
inputs=[
|
311 |
-
outputs=[
|
312 |
)
|
313 |
|
314 |
submit_button.click(
|
315 |
-
fn=
|
316 |
inputs=[
|
317 |
-
|
318 |
model_name,
|
319 |
generating_batch_size,
|
320 |
temperature,
|
321 |
],
|
322 |
outputs=[
|
323 |
description_output,
|
324 |
-
|
325 |
input_analysis_output,
|
326 |
example_briefs_output,
|
327 |
-
|
328 |
-
|
329 |
],
|
330 |
)
|
331 |
|
332 |
generate_description_button.click(
|
333 |
-
fn=
|
334 |
-
inputs=[
|
335 |
outputs=[description_output],
|
336 |
)
|
337 |
|
338 |
generate_examples_directly_button.click(
|
339 |
-
fn=
|
340 |
inputs=[
|
341 |
description_output,
|
342 |
-
|
343 |
generating_batch_size,
|
344 |
model_name,
|
345 |
temperature,
|
346 |
],
|
347 |
-
outputs=[
|
348 |
)
|
349 |
|
350 |
analyze_input_button.click(
|
351 |
-
fn=
|
352 |
inputs=[description_output, model_name, temperature],
|
353 |
outputs=[input_analysis_output],
|
354 |
)
|
355 |
|
356 |
generate_briefs_button.click(
|
357 |
-
fn=
|
358 |
inputs=[
|
359 |
description_output,
|
360 |
input_analysis_output,
|
@@ -366,40 +392,40 @@ with gr.Blocks(title="Task Description Generator") as demo:
|
|
366 |
)
|
367 |
|
368 |
generate_examples_from_briefs_button.click(
|
369 |
-
fn=
|
370 |
inputs=[
|
371 |
description_output,
|
372 |
example_briefs_output,
|
373 |
-
|
374 |
generating_batch_size,
|
375 |
model_name,
|
376 |
temperature,
|
377 |
],
|
378 |
-
outputs=[
|
379 |
)
|
380 |
|
381 |
-
|
382 |
-
fn=
|
383 |
-
inputs=[
|
384 |
-
outputs=[selected_example_input, selected_example_output, selected_row_index, delete_row_button],
|
385 |
)
|
386 |
|
387 |
-
|
388 |
-
fn=
|
389 |
-
inputs=[
|
390 |
-
outputs=[selected_example_input, selected_example_output, delete_row_button],
|
391 |
)
|
392 |
|
393 |
-
|
394 |
-
fn=
|
395 |
-
inputs=[
|
396 |
-
outputs=[selected_example_input, selected_example_output, delete_row_button],
|
397 |
)
|
398 |
|
399 |
-
|
400 |
-
fn=
|
401 |
-
inputs=[
|
402 |
-
outputs=[selected_example_input, selected_example_output, delete_row_button],
|
403 |
)
|
404 |
|
405 |
gr.Markdown("### Manual Flagging", visible=False)
|
@@ -411,26 +437,44 @@ with gr.Blocks(title="Task Description Generator") as demo:
|
|
411 |
flag_button.click(
|
412 |
lambda *args: flagging_callback.flag(args),
|
413 |
inputs=[
|
414 |
-
|
415 |
model_name,
|
416 |
generating_batch_size,
|
417 |
description_output,
|
418 |
-
|
419 |
flag_reason,
|
420 |
],
|
421 |
outputs=[],
|
422 |
)
|
423 |
|
424 |
append_example_button.click(
|
425 |
-
fn=
|
426 |
-
inputs=[selected_example_input, selected_example_output,
|
427 |
-
outputs=[
|
428 |
)
|
429 |
|
430 |
delete_row_button.click(
|
431 |
-
fn=
|
432 |
-
inputs=[selected_row_index,
|
433 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
)
|
435 |
|
436 |
if __name__ == "__main__":
|
|
|
5 |
from langchain_openai import ChatOpenAI
|
6 |
from meta_prompt.sample_generator import TaskDescriptionGenerator
|
7 |
|
8 |
+
def convert_examples_to_json(examples):
|
9 |
pd_examples = pd.DataFrame(examples)
|
10 |
pd_examples.columns = pd_examples.columns.str.lower()
|
11 |
return pd_examples.to_json(orient="records")
|
12 |
|
13 |
+
def process_json_data(
|
14 |
examples, model_name, generating_batch_size, temperature
|
15 |
):
|
16 |
try:
|
17 |
# Convert the gradio dataframe into a JSON array
|
18 |
+
input_json = convert_examples_to_json(examples)
|
19 |
|
20 |
model = ChatOpenAI(
|
21 |
model=model_name, temperature=temperature, max_retries=3
|
|
|
50 |
except Exception as e:
|
51 |
raise gr.Error(f"An error occurred: {str(e)}")
|
52 |
|
53 |
+
def generate_description(examples, model_name, temperature):
|
54 |
try:
|
55 |
+
input_json = convert_examples_to_json(examples)
|
56 |
|
57 |
model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
|
58 |
generator = TaskDescriptionGenerator(model)
|
|
|
61 |
except Exception as e:
|
62 |
raise gr.Error(f"An error occurred: {str(e)}")
|
63 |
|
64 |
+
def analyze_input_data(description, model_name, temperature):
|
65 |
try:
|
66 |
model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
|
67 |
generator = TaskDescriptionGenerator(model)
|
|
|
70 |
except Exception as e:
|
71 |
raise gr.Error(f"An error occurred: {str(e)}")
|
72 |
|
73 |
+
def generate_example_briefs(
|
74 |
description, input_analysis, generating_batch_size, model_name, temperature
|
75 |
):
|
76 |
try:
|
|
|
86 |
raise gr.Error(f"An error occurred: {str(e)}")
|
87 |
|
88 |
|
89 |
+
def generate_examples_using_briefs(
|
90 |
description, new_example_briefs, examples, generating_batch_size, model_name, temperature
|
91 |
):
|
92 |
try:
|
93 |
+
input_json = convert_examples_to_json(examples)
|
94 |
model = ChatOpenAI(
|
95 |
model=model_name, temperature=temperature, max_retries=3
|
96 |
)
|
|
|
107 |
raise gr.Error(f"An error occurred: {str(e)}")
|
108 |
|
109 |
|
110 |
+
def generate_examples_from_description(
|
111 |
description, raw_example, generating_batch_size, model_name, temperature
|
112 |
):
|
113 |
try:
|
114 |
+
input_json = convert_examples_to_json(raw_example)
|
115 |
model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
|
116 |
generator = TaskDescriptionGenerator(model)
|
117 |
result = generator.generate_examples_directly(
|
|
|
125 |
raise gr.Error(f"An error occurred: {str(e)}")
|
126 |
|
127 |
|
128 |
+
def format_selected_input_example_dataframe(evt: gr.SelectData, examples):
|
129 |
if evt.index[0] < len(examples):
|
130 |
selected_example = examples.iloc[evt.index[0]]
|
131 |
return (
|
132 |
selected_example.iloc[0],
|
133 |
selected_example.iloc[1],
|
134 |
evt.index[0] + 1,
|
135 |
+
gr.update(visible=True), # Show selected_example_group
|
136 |
+
gr.update(visible=True), # Show selected_row_index
|
137 |
+
gr.update(visible=True), # Show delete_row_button
|
138 |
+
gr.update(visible=True), # Show update_row_button
|
139 |
+
gr.update(visible=False), # Hide append_example_button
|
140 |
)
|
141 |
+
return "", "", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
142 |
|
143 |
+
def format_selected_example(evt: gr.SelectData, examples):
|
144 |
if evt.index[0] < len(examples):
|
145 |
selected_example = examples.iloc[evt.index[0]]
|
146 |
return (
|
147 |
selected_example.iloc[0],
|
148 |
selected_example.iloc[1],
|
149 |
+
gr.update(visible=True), # Show selected_example_group
|
150 |
+
gr.update(visible=False), # Hide selected_row_index
|
151 |
+
gr.update(visible=False), # Hide delete_row_button
|
152 |
+
gr.update(visible=False), # Hide update_row_button
|
153 |
+
gr.update(visible=True), # Show append_example_button
|
154 |
)
|
155 |
+
return "", "", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
156 |
|
157 |
+
def import_json_data(file, input_dataframe):
|
158 |
if file is not None:
|
159 |
df = pd.read_json(file.name)
|
160 |
# Uppercase the first letter of each column name
|
161 |
df.columns = df.columns.str.title()
|
162 |
return df
|
163 |
+
return input_dataframe
|
164 |
|
165 |
+
def export_json_data(dataframe):
|
166 |
+
if dataframe is not None and not dataframe.empty:
|
167 |
# Copy the dataframe and lowercase the column names
|
168 |
+
df_copy = dataframe.copy()
|
169 |
df_copy.columns = df_copy.columns.str.lower()
|
170 |
|
171 |
json_str = df_copy.to_json(orient="records", indent=2)
|
|
|
178 |
return temp_file_path
|
179 |
return None
|
180 |
|
181 |
+
def append_example_to_input_dataframe(new_example_input, new_example_output, input_dataframe):
|
182 |
try:
|
183 |
new_row = pd.DataFrame([[new_example_input, new_example_output]], columns=['Input', 'Output'])
|
184 |
+
updated_df = pd.concat([input_dataframe, new_row], ignore_index=True)
|
185 |
+
return updated_df, "", "", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
186 |
except KeyError:
|
187 |
raise gr.Error("Invalid input or output")
|
188 |
|
189 |
+
def delete_selected_dataframe_row(row_index, input_dataframe):
|
190 |
if row_index is not None and row_index > 0:
|
191 |
# Subtract 1 from row_index because it's 1-indexed for display
|
192 |
+
input_dataframe = input_dataframe.drop(index=row_index - 1).reset_index(drop=True)
|
193 |
+
return input_dataframe, None, "", "", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False) # Return updated df, clear row index and selected example, hide selected_example_group, selected_row_index, delete_row_button, and update_row_button
|
194 |
+
return input_dataframe, row_index, "", "", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False) # Return unchanged if no valid row index, hide selected_example_group, selected_row_index, delete_row_button, and update_row_button
|
195 |
+
|
196 |
+
def update_selected_dataframe_row(selected_example_input, selected_example_output, selected_row_index, input_dataframe):
|
197 |
+
if selected_row_index is not None and selected_row_index > 0:
|
198 |
+
# Subtract 1 from selected_row_index because it's 1-indexed for display
|
199 |
+
input_dataframe.iloc[selected_row_index - 1] = [selected_example_input, selected_example_output]
|
200 |
+
return input_dataframe, "", "", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False) # Return updated df, clear selected example, hide selected_example_group, selected_row_index, delete_row_button, and update_row_button
|
201 |
+
return input_dataframe, selected_example_input, selected_example_output, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False) # Return unchanged if no valid row index, hide selected_example_group, selected_row_index, delete_row_button, and update_row_button
|
202 |
+
|
203 |
+
def clear_selected_example_group(input_dataframe):
|
204 |
+
if input_dataframe.empty:
|
205 |
+
return gr.update(visible=False)
|
206 |
+
return None
|
207 |
|
208 |
with gr.Blocks(title="Task Description Generator") as demo:
|
209 |
gr.Markdown("# Task Description Generator")
|
|
|
212 |
)
|
213 |
|
214 |
|
215 |
+
|
216 |
+
input_dataframe = gr.DataFrame(
|
217 |
label="Input Examples",
|
218 |
headers=["Input", "Output"],
|
219 |
datatype=["str", "str"],
|
220 |
row_count=(1, "dynamic"),
|
221 |
col_count=(2, "fixed"),
|
222 |
+
interactive=False
|
223 |
)
|
224 |
+
with (selected_example_group := gr.Group(visible=False)):
|
225 |
+
with gr.Row():
|
226 |
+
selected_row_index = gr.Number(label="Selected Row Index", value=None, precision=0, visible=False)
|
227 |
+
delete_row_button = gr.Button("Delete Selected Row", variant="secondary", visible=False)
|
228 |
with gr.Row():
|
229 |
selected_example_input = gr.Textbox(label="Selected Example Input", lines=2, show_copy_button=True)
|
230 |
selected_example_output = gr.Textbox(label="Selected Example Output", lines=2, show_copy_button=True)
|
231 |
with gr.Row():
|
232 |
+
update_row_button = gr.Button("Update Selected Row", variant="secondary", visible=False)
|
233 |
+
append_example_button = gr.Button("Append to Input Examples", variant="secondary", visible=False)
|
234 |
+
with gr.Row():
|
235 |
+
close_button = gr.Button("Close", variant="secondary")
|
236 |
with gr.Row():
|
237 |
submit_button = gr.Button("Generate", variant="primary")
|
238 |
with gr.Accordion("Import/Export JSON", open=False):
|
239 |
+
json_file_object = gr.File(
|
240 |
label="Import/Export JSON", file_types=[".json"], type="filepath"
|
241 |
)
|
242 |
export_button = gr.Button("Export to JSON")
|
|
|
274 |
analyze_input_button = gr.Button(
|
275 |
"Analyze Input", variant="secondary"
|
276 |
)
|
277 |
+
examples_directly_output_dataframe = gr.DataFrame(
|
278 |
label="Examples Directly",
|
279 |
headers=["Input", "Output"],
|
280 |
interactive=False,
|
|
|
294 |
generate_examples_from_briefs_button = gr.Button(
|
295 |
"Generate Examples from Briefs", variant="secondary"
|
296 |
)
|
297 |
+
examples_from_briefs_output_dataframe = gr.DataFrame(
|
298 |
label="Examples from Briefs",
|
299 |
headers=["Input", "Output"],
|
300 |
interactive=False,
|
|
|
302 |
row_count=(1, "dynamic"),
|
303 |
col_count=(2, "fixed"),
|
304 |
)
|
305 |
+
examples_output_dataframe = gr.DataFrame(
|
306 |
label="Examples",
|
307 |
headers=["Input", "Output"],
|
308 |
interactive=False,
|
|
|
313 |
|
314 |
clear_button = gr.ClearButton(
|
315 |
[
|
316 |
+
input_dataframe,
|
317 |
description_output,
|
318 |
input_analysis_output,
|
319 |
example_briefs_output,
|
320 |
+
examples_from_briefs_output_dataframe,
|
321 |
+
examples_output_dataframe,
|
322 |
selected_example_input,
|
323 |
selected_example_output,
|
324 |
],
|
325 |
value="Clear All"
|
326 |
)
|
327 |
|
328 |
+
json_file_object.change(
|
329 |
+
fn=import_json_data,
|
330 |
+
inputs=[json_file_object, input_dataframe],
|
331 |
+
outputs=[input_dataframe],
|
332 |
)
|
333 |
|
334 |
export_button.click(
|
335 |
+
fn=export_json_data,
|
336 |
+
inputs=[input_dataframe],
|
337 |
+
outputs=[json_file_object],
|
338 |
)
|
339 |
|
340 |
submit_button.click(
|
341 |
+
fn=process_json_data,
|
342 |
inputs=[
|
343 |
+
input_dataframe,
|
344 |
model_name,
|
345 |
generating_batch_size,
|
346 |
temperature,
|
347 |
],
|
348 |
outputs=[
|
349 |
description_output,
|
350 |
+
examples_directly_output_dataframe,
|
351 |
input_analysis_output,
|
352 |
example_briefs_output,
|
353 |
+
examples_from_briefs_output_dataframe,
|
354 |
+
examples_output_dataframe,
|
355 |
],
|
356 |
)
|
357 |
|
358 |
generate_description_button.click(
|
359 |
+
fn=generate_description,
|
360 |
+
inputs=[input_dataframe, model_name, temperature],
|
361 |
outputs=[description_output],
|
362 |
)
|
363 |
|
364 |
generate_examples_directly_button.click(
|
365 |
+
fn=generate_examples_from_description,
|
366 |
inputs=[
|
367 |
description_output,
|
368 |
+
input_dataframe,
|
369 |
generating_batch_size,
|
370 |
model_name,
|
371 |
temperature,
|
372 |
],
|
373 |
+
outputs=[examples_directly_output_dataframe],
|
374 |
)
|
375 |
|
376 |
analyze_input_button.click(
|
377 |
+
fn=analyze_input_data,
|
378 |
inputs=[description_output, model_name, temperature],
|
379 |
outputs=[input_analysis_output],
|
380 |
)
|
381 |
|
382 |
generate_briefs_button.click(
|
383 |
+
fn=generate_example_briefs,
|
384 |
inputs=[
|
385 |
description_output,
|
386 |
input_analysis_output,
|
|
|
392 |
)
|
393 |
|
394 |
generate_examples_from_briefs_button.click(
|
395 |
+
fn=generate_examples_using_briefs,
|
396 |
inputs=[
|
397 |
description_output,
|
398 |
example_briefs_output,
|
399 |
+
input_dataframe,
|
400 |
generating_batch_size,
|
401 |
model_name,
|
402 |
temperature,
|
403 |
],
|
404 |
+
outputs=[examples_from_briefs_output_dataframe],
|
405 |
)
|
406 |
|
407 |
+
input_dataframe.select(
|
408 |
+
fn=format_selected_input_example_dataframe,
|
409 |
+
inputs=[input_dataframe],
|
410 |
+
outputs=[selected_example_input, selected_example_output, selected_row_index, selected_example_group, selected_row_index, delete_row_button, update_row_button, append_example_button],
|
411 |
)
|
412 |
|
413 |
+
examples_directly_output_dataframe.select(
|
414 |
+
fn=format_selected_example,
|
415 |
+
inputs=[examples_directly_output_dataframe],
|
416 |
+
outputs=[selected_example_input, selected_example_output, selected_example_group, selected_row_index, delete_row_button, update_row_button, append_example_button],
|
417 |
)
|
418 |
|
419 |
+
examples_from_briefs_output_dataframe.select(
|
420 |
+
fn=format_selected_example,
|
421 |
+
inputs=[examples_from_briefs_output_dataframe],
|
422 |
+
outputs=[selected_example_input, selected_example_output, selected_example_group, selected_row_index, delete_row_button, update_row_button, append_example_button],
|
423 |
)
|
424 |
|
425 |
+
examples_output_dataframe.select(
|
426 |
+
fn=format_selected_example,
|
427 |
+
inputs=[examples_output_dataframe],
|
428 |
+
outputs=[selected_example_input, selected_example_output, selected_example_group, selected_row_index, delete_row_button, update_row_button, append_example_button],
|
429 |
)
|
430 |
|
431 |
gr.Markdown("### Manual Flagging", visible=False)
|
|
|
437 |
flag_button.click(
|
438 |
lambda *args: flagging_callback.flag(args),
|
439 |
inputs=[
|
440 |
+
input_dataframe,
|
441 |
model_name,
|
442 |
generating_batch_size,
|
443 |
description_output,
|
444 |
+
examples_output_dataframe,
|
445 |
flag_reason,
|
446 |
],
|
447 |
outputs=[],
|
448 |
)
|
449 |
|
450 |
append_example_button.click(
|
451 |
+
fn=append_example_to_input_dataframe,
|
452 |
+
inputs=[selected_example_input, selected_example_output, input_dataframe],
|
453 |
+
outputs=[input_dataframe, selected_example_input, selected_example_output, selected_example_group, selected_row_index, delete_row_button, update_row_button, append_example_button],
|
454 |
)
|
455 |
|
456 |
delete_row_button.click(
|
457 |
+
fn=delete_selected_dataframe_row,
|
458 |
+
inputs=[selected_row_index, input_dataframe],
|
459 |
+
outputs=[input_dataframe, selected_row_index, selected_example_input, selected_example_output, selected_example_group, selected_row_index, delete_row_button, update_row_button],
|
460 |
+
)
|
461 |
+
|
462 |
+
update_row_button.click(
|
463 |
+
fn=update_selected_dataframe_row,
|
464 |
+
inputs=[selected_example_input, selected_example_output, selected_row_index, input_dataframe],
|
465 |
+
outputs=[input_dataframe, selected_example_input, selected_example_output, selected_example_group, selected_row_index, delete_row_button, update_row_button],
|
466 |
+
)
|
467 |
+
|
468 |
+
close_button.click(
|
469 |
+
fn=lambda: gr.update(visible=False),
|
470 |
+
inputs=[],
|
471 |
+
outputs=[selected_example_group],
|
472 |
+
)
|
473 |
+
|
474 |
+
input_dataframe.change(
|
475 |
+
fn=clear_selected_example_group,
|
476 |
+
inputs=[input_dataframe],
|
477 |
+
outputs=[selected_example_group],
|
478 |
)
|
479 |
|
480 |
if __name__ == "__main__":
|