Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UI #600

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/unitxt/ui/load_catalog_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def get_from_str(template_str):
else:
templates = set()
for item in template_data:
templates.update(get_from_str(item))
if isinstance(item, str):
templates.update(get_from_str(item))
# templates.add("templates.key_val_with_new_lines")
templates_jsons = {
template: safe_load_json(get_file_from_item_name(template))
Expand Down Expand Up @@ -86,9 +87,9 @@ def is_valid_data(data):
)
formats, formats_jsons = get_catalog_items("formats")
json_data.update(formats_jsons)
instructions, instructiosn_jsons = get_catalog_items("instructions")
json_data.update(instructiosn_jsons)
return cards_data, json_data, formats, instructions
system_prompts, system_prompts_jsons = get_catalog_items("system_prompts")
json_data.update(system_prompts_jsons)
return cards_data, json_data, formats, system_prompts


def check_augmentable(task_name):
Expand Down Expand Up @@ -140,12 +141,12 @@ def get_catalog_items(items_type):


if __name__ == "__main__":
data, jsons, formats, instructions = load_cards_data()
data, jsons, formats, system_prompts = load_cards_data()
stuff = {
"cards_data": data,
"jsons": jsons,
"formats": formats,
"instructions": instructions,
"system_prompts": system_prompts,
}
for bla in stuff:
with open(f"{bla}.txt", "w") as file:
Expand Down
34 changes: 18 additions & 16 deletions src/unitxt/ui/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
get_templates,
hash_dict,
increase_num,
instructions_items,
jsons,
system_prompts_items,
update_choices_per_task,
)

Expand All @@ -43,7 +43,7 @@ def run_unitxt_entry(
task,
dataset,
template,
instruction=None,
system_prompt=None,
format=None,
num_demos=0,
augmentor=None,
Expand All @@ -60,8 +60,8 @@ def run_unitxt_entry(

return msg, "", "", config.EMPTY_SCORES_FRAME, config.EMPTY_SCORES_FRAME, ""

if not isinstance(instruction, str):
instruction = None
if not isinstance(system_prompt, str):
system_prompt = None
if not isinstance(format, str):
format = None
if not isinstance(num_demos, int):
Expand All @@ -75,7 +75,7 @@ def run_unitxt_entry(
return run_unitxt(
dataset,
template,
instruction,
system_prompt,
format,
num_demos,
augmentor,
Expand All @@ -89,7 +89,7 @@ def run_unitxt_entry(
def run_unitxt(
dataset,
template,
instruction=None,
system_prompt=None,
format=None,
num_demos=0,
augmentor=None,
Expand All @@ -100,7 +100,7 @@ def run_unitxt(
index = index - 1
try:
prompts_list, prompt_args = get_prompts(
dataset, template, num_demos, instruction, format, augmentor
dataset, template, num_demos, system_prompt, format, augmentor
)
selected_prompt = prompts_list[index]
prompt_text = selected_prompt[config.PROMPT_SOURCE_STR]
Expand Down Expand Up @@ -204,12 +204,12 @@ def display_json_button(element: str):
variant="secondary",
)

instructions = gr.Dropdown(
choices=[None, *instructions_items],
label="Instruction",
system_prompts = gr.Dropdown(
choices=[None, *system_prompts_items],
label="System Prompt",
scale=5,
)
instructions_js_button = gr.Button(
system_prompts_js_button = gr.Button(
config.JSON_BUTTON_TXT,
scale=1,
size="sm",
Expand Down Expand Up @@ -321,11 +321,13 @@ def display_json_button(element: str):
templates_js_button.click(
display_json_button, templates, [tabs, json_intro, element_name, json_viewer]
)
instructions.select(activate_button, outputs=instructions_js_button).then(
system_prompts.select(activate_button, outputs=system_prompts_js_button).then(
activate_button, outputs=generate_prompts_button
).then(deactivate_button, outputs=infer_button)
instructions_js_button.click(
display_json_button, instructions, [tabs, json_intro, element_name, json_viewer]
system_prompts_js_button.click(
display_json_button,
system_prompts,
[tabs, json_intro, element_name, json_viewer],
)
formats.select(activate_button, outputs=formats_js_button).then(
activate_button, outputs=generate_prompts_button
Expand All @@ -344,7 +346,7 @@ def display_json_button(element: str):
tasks,
cards,
templates,
instructions,
system_prompts,
formats,
num_shots,
augmentors,
Expand Down Expand Up @@ -374,7 +376,7 @@ def display_json_button(element: str):
deactivate_button, outputs=cards_js_button
).then(deactivate_button, outputs=templates_js_button).then(
deactivate_button, outputs=formats_js_button
).then(deactivate_button, outputs=instructions_js_button)
).then(deactivate_button, outputs=system_prompts_js_button)

# GENERATE PROMPT BUTTON LOGIC
generate_prompts_button.click(
Expand Down
6 changes: 3 additions & 3 deletions src/unitxt/ui/ui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .load_catalog_data import get_catalog_items, load_cards_data

logger = get_logger()
data, jsons, formats_items, instructions_items = load_cards_data()
data, jsons, formats_items, system_prompts_items = load_cards_data()


def conditionally_activate_button(conditional_element, button):
Expand All @@ -39,13 +39,13 @@ def safe_add(parameter, key, args):


@lru_cache
def get_prompts(dataset, template, num_demos, instruction, format, augmentor):
def get_prompts(dataset, template, num_demos, system_prompt, format, augmentor):
prompt_args = {"card": dataset, "template": template, config.LOADER_LIMIT_STR: 300}
if num_demos != 0:
prompt_args.update(
{"num_demos": num_demos, "demos_pool_size": config.DEMOS_POOL_SIZE}
)
safe_add(instruction, "instruction", prompt_args)
safe_add(system_prompt, "system_prompt", prompt_args)
safe_add(format, "format", prompt_args)
safe_add(augmentor, "augmentor", prompt_args)

Expand Down
Loading