DSXiangLi commited on
Commit
15fc122
1 Parent(s): b581f0e
Files changed (2) hide show
  1. app.py +99 -99
  2. requirements.txt +1 -1
app.py CHANGED
@@ -8,84 +8,84 @@ from self.generate import init_instance, generate_instruction
8
  from self.prompt import self_prompt
9
 
10
  with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as demo:
11
- # gr.Markdown("# Automatic Prompt Engineer")
12
- # with gr.Row():
13
- # with gr.Column(scale=2):
14
- # gr.Markdown("## 第一步:输入参数")
15
- # with gr.Row():
16
- # openai_key = gr.Textbox(type='password', label='输入 API key')
17
- # with gr.Row():
18
- # n_train = gr.Slider(label="训练样本数", minimum=1, maximum=20, step=1, value=5)
19
- # n_few_shot = gr.Slider(label="每组几个样例", minimum=1, maximum=20, step=1, value=5)
20
- #
21
- # with gr.Row():
22
- # n_eval = gr.Slider(label="评估样本数", minimum=1, maximum=30, step=5, value=20)
23
- #
24
- # with gr.Column(scale=3):
25
- # gr.Markdown("## 第二步:加载数据(选任务或上传数据)")
26
- # with gr.Tab("选择数据"):
27
- # with gr.Row():
28
- # file = gr.File(label='上传txt文件,input[空格]output[换行]')
29
- # with gr.Row():
30
- # task = gr.Dropdown(label="Chosse Existing Task", choices=list(LoadFactory.keys()), value=None)
31
- # with gr.Row():
32
- # instance = gr.State()
33
- # load_button = gr.Button("Load Task")
34
- # load_flag = gr.Textbox()
35
- # sample_button = gr.Button('sample Data')
36
- # sample_flag = gr.Textbox()
37
- #
38
- # with gr.Tab("展示数据"):
39
- # with gr.Row():
40
- # train_str = gr.Textbox(max_lines=100, lines=10, label="Data for prompt generation")
41
- # eval_str = gr.Textbox(max_lines=100, lines=10, label="Data for scoring")
42
- #
43
- # with gr.Row():
44
- # with gr.Column(scale=2):
45
- # gr.Markdown("## 第三步: Run APE(可替换默认指令)")
46
- # gen_prompt = gr.Textbox(max_lines=100, lines=3, interative=True,
47
- # placeholder=MyTemplate['gen_user_prompt'],
48
- # value='', label="Prompt for generation")
49
- # eval_prompt = gr.Textbox(max_lines=100, lines=3, interative=True,
50
- # placeholder=MyTemplate['eval_prompt'],
51
- # value='', label="Prompt for Evaluation")
52
- # test_prompt = gr.Textbox(max_lines=100, lines=3, interative=True,
53
- # placeholder=MyTemplate['test_prompt'],
54
- # value='', label="Prompt for Single Test")
55
- #
56
- # with gr.Row():
57
- # cost = gr.Textbox(lines=1, value="", label="Estimated Cost ($)")
58
- # cost_button = gr.Button("Estimate Cost")
59
- # with gr.Row():
60
- # gen_button = gr.Button("Generate")
61
- # eval_button = gr.Button("Eval")
62
- #
63
- # with gr.Column(scale=3):
64
- # gr.Markdown("## 第四步:APE 结果")
65
- # with gr.Tab("生成指令"):
66
- # all_prompt = gr.Textbox(label='Generated Prompt')
67
- # # Display all generated prompt with log probs
68
- # output_df = gr.DataFrame(type='pandas', headers=['Prompt', 'Likelihood'], wrap=True, interactive=False)
69
- #
70
- # with gr.Tab("指令单测"):
71
- # # Test the output of LLM using prompt
72
- # with gr.Row():
73
- # with gr.Column(scale=1):
74
- # test_instruction = gr.Textbox(lines=4, value="", label="Prompt to test")
75
- # test_input = gr.Textbox(lines=4, value="", label="Inputs used to test prompt[多个输入以换行分割]")
76
- # test_button = gr.Button("Test")
77
- # with gr.Column(scale=1):
78
- # test_output = gr.Textbox(lines=9, value="", label="Model Output")
79
- #
80
- # with gr.Tab("指令评估"):
81
- # # By Default use the Evaluation Set in APE
82
- # with gr.Row():
83
- # with gr.Column(scale=1):
84
- # score_instruction = gr.Textbox(lines=3, value="",
85
- # label="Prompt to Evaluate")
86
- # score_button = gr.Button("Evaluate")
87
- # with gr.Column(scale=1):
88
- # test_score = gr.Textbox(lines=1, value="", label="Log(p)", disabled=True)
89
 
90
  gr.Markdown('\n\n')
91
  gr.Markdown('--------')
@@ -123,27 +123,27 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
123
  """
124
  APE Callback
125
  """
126
- # # 1. 选择已有任务/上传文件,实例化Instance
127
- # load_button.click(load_task, [task, file], [instance, load_flag])
128
- #
129
- # # 2. 按 Configuration Sample数据 得到训练样本和验证集, 并在前端展示。支持重采样
130
- # sample_button.click(sample_data, [instance, n_train, n_few_shot, n_eval],
131
- # [train_str, eval_str, instance, sample_flag])
132
- #
133
- # # 3. Estimate Cost for train + Eval
134
- # cost_button.click(esttimate_cost, [instance], [cost])
135
- #
136
- # # 4. Run APE -> 所有指令
137
- # gen_button.click(generate, [gen_prompt, instance, openai_key], [all_prompt])
138
- #
139
- # # 5. Evaluate -> 得到所有指令的Log Prob
140
- # eval_button.click(evaluate, [eval_prompt, all_prompt, instance, openai_key], [output_df])
141
- #
142
- # # 6. 输入指令单测
143
- # test_button.click(single_test, [test_prompt, test_instruction, test_input, openai_key], [test_output])
144
- #
145
- # # 7. 输入指令打分
146
- # score_button.click(score_single, [eval_prompt, instance, score_instruction, openai_key], [test_score])
147
 
148
  """
149
  SELF Callback
 
8
  from self.prompt import self_prompt
9
 
10
  with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as demo:
11
+ gr.Markdown("# Automatic Prompt Engineer")
12
+ with gr.Row():
13
+ with gr.Column(scale=2):
14
+ gr.Markdown("## 第一步:输入参数")
15
+ with gr.Row():
16
+ openai_key = gr.Textbox(type='password', label='输入 API key')
17
+ with gr.Row():
18
+ n_train = gr.Slider(label="训练样本数", minimum=1, maximum=20, step=1, value=5)
19
+ n_few_shot = gr.Slider(label="每组几个样例", minimum=1, maximum=20, step=1, value=5)
20
+
21
+ with gr.Row():
22
+ n_eval = gr.Slider(label="评估样本数", minimum=1, maximum=30, step=5, value=20)
23
+
24
+ with gr.Column(scale=3):
25
+ gr.Markdown("## 第二步:加载数据(选任务或上传数据)")
26
+ with gr.Tab("选择数据"):
27
+ with gr.Row():
28
+ file = gr.File(label='上传txt文件,input[空格]output[换行]')
29
+ with gr.Row():
30
+ task = gr.Dropdown(label="Chosse Existing Task", choices=list(LoadFactory.keys()), value=None)
31
+ with gr.Row():
32
+ instance = gr.State()
33
+ load_button = gr.Button("Load Task")
34
+ load_flag = gr.Textbox()
35
+ sample_button = gr.Button('sample Data')
36
+ sample_flag = gr.Textbox()
37
+
38
+ with gr.Tab("展示数据"):
39
+ with gr.Row():
40
+ train_str = gr.Textbox(max_lines=100, lines=10, label="Data for prompt generation")
41
+ eval_str = gr.Textbox(max_lines=100, lines=10, label="Data for scoring")
42
+
43
+ with gr.Row():
44
+ with gr.Column(scale=2):
45
+ gr.Markdown("## 第三步: Run APE(可替换默认指令)")
46
+ gen_prompt = gr.Textbox(max_lines=100, lines=3, interative=True,
47
+ placeholder=MyTemplate['gen_user_prompt'],
48
+ value='', label="Prompt for generation")
49
+ eval_prompt = gr.Textbox(max_lines=100, lines=3, interative=True,
50
+ placeholder=MyTemplate['eval_prompt'],
51
+ value='', label="Prompt for Evaluation")
52
+ test_prompt = gr.Textbox(max_lines=100, lines=3, interative=True,
53
+ placeholder=MyTemplate['test_prompt'],
54
+ value='', label="Prompt for Single Test")
55
+
56
+ with gr.Row():
57
+ cost = gr.Textbox(lines=1, value="", label="Estimated Cost ($)")
58
+ cost_button = gr.Button("Estimate Cost")
59
+ with gr.Row():
60
+ gen_button = gr.Button("Generate")
61
+ eval_button = gr.Button("Eval")
62
+
63
+ with gr.Column(scale=3):
64
+ gr.Markdown("## 第四步:APE 结果")
65
+ with gr.Tab("生成指令"):
66
+ all_prompt = gr.Textbox(label='Generated Prompt')
67
+ # Display all generated prompt with log probs
68
+ output_df = gr.DataFrame(type='pandas', headers=['Prompt', 'Likelihood'], wrap=True, interactive=False)
69
+
70
+ with gr.Tab("指令单测"):
71
+ # Test the output of LLM using prompt
72
+ with gr.Row():
73
+ with gr.Column(scale=1):
74
+ test_instruction = gr.Textbox(lines=4, value="", label="Prompt to test")
75
+ test_input = gr.Textbox(lines=4, value="", label="Inputs used to test prompt[多个输入以换行分割]")
76
+ test_button = gr.Button("Test")
77
+ with gr.Column(scale=1):
78
+ test_output = gr.Textbox(lines=9, value="", label="Model Output")
79
+
80
+ with gr.Tab("指令评估"):
81
+ # By Default use the Evaluation Set in APE
82
+ with gr.Row():
83
+ with gr.Column(scale=1):
84
+ score_instruction = gr.Textbox(lines=3, value="",
85
+ label="Prompt to Evaluate")
86
+ score_button = gr.Button("Evaluate")
87
+ with gr.Column(scale=1):
88
+ test_score = gr.Textbox(lines=1, value="", label="Log(p)", disabled=True)
89
 
90
  gr.Markdown('\n\n')
91
  gr.Markdown('--------')
 
123
  """
124
  APE Callback
125
  """
126
+ # 1. 选择已有任务/上传文件,实例化Instance
127
+ load_button.click(load_task, [task, file], [instance, load_flag])
128
+
129
+ # 2. 按 Configuration Sample数据 得到训练样本和验证集, 并在前端展示。支持重采样
130
+ sample_button.click(sample_data, [instance, n_train, n_few_shot, n_eval],
131
+ [train_str, eval_str, instance, sample_flag])
132
+
133
+ # 3. Estimate Cost for train + Eval
134
+ cost_button.click(esttimate_cost, [instance], [cost])
135
+
136
+ # 4. Run APE -> 所有指令
137
+ gen_button.click(generate, [gen_prompt, instance, openai_key], [all_prompt])
138
+
139
+ # 5. Evaluate -> 得到所有指令的Log Prob
140
+ eval_button.click(evaluate, [eval_prompt, all_prompt, instance, openai_key], [output_df])
141
+
142
+ # 6. 输入指令单测
143
+ test_button.click(single_test, [test_prompt, test_instruction, test_input, openai_key], [test_output])
144
+
145
+ # 7. 输入指令打分
146
+ score_button.click(score_single, [eval_prompt, instance, score_instruction, openai_key], [test_score])
147
 
148
  """
149
  SELF Callback
requirements.txt CHANGED
@@ -3,4 +3,4 @@ gradio==3.21.0
3
  langchain==0.0.113
4
  tiktoken==0.1.2
5
  sentence-transformers==2.2.2
6
- pandas==1.5.3
 
3
  langchain==0.0.113
4
  tiktoken==0.1.2
5
  sentence-transformers==2.2.2
6
+ rouge_score