Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,14 +7,12 @@ import gradio as gr
|
|
| 7 |
model = EncoderDecoderModel.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c_fc")
|
| 8 |
tokenizer = RobertaTokenizer.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c_fc")
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# elif gen_mode=="Function":
|
| 17 |
-
# input_desc = "GENERATE BOTH CHANNEL AND FUNCTION FOR TRIGGER AND ACTION <pf> " + input_desc
|
| 18 |
|
| 19 |
input_ids = tokenizer.encode(desc, return_tensors='pt')
|
| 20 |
|
|
@@ -22,8 +20,49 @@ def generate_preds(desc):
|
|
| 22 |
preds = model.generate(
|
| 23 |
input_ids,
|
| 24 |
max_length=100,
|
| 25 |
-
num_beams=
|
| 26 |
-
num_return_sequences=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
early_stopping=True
|
| 28 |
)
|
| 29 |
|
|
@@ -31,28 +70,22 @@ def generate_preds(desc):
|
|
| 31 |
for item in preds:
|
| 32 |
output_list.append(tokenizer.decode(item, skip_special_tokens=True))
|
| 33 |
|
| 34 |
-
# if gen_mode=="Channel":
|
| 35 |
trigger = [x.split("<sep>")[0].strip() for x in output_list]
|
| 36 |
-
|
|
|
|
| 37 |
action = [x.split("<sep>")[1].strip() for x in output_list]
|
| 38 |
-
|
|
|
|
| 39 |
df = {"Trigger": trigger,
|
| 40 |
-
|
|
|
|
| 41 |
"Action": action,
|
| 42 |
-
|
|
|
|
| 43 |
}
|
| 44 |
-
# elif gen_mode=="Function":
|
| 45 |
-
# trigger = [x.split("<sep>")[1].strip() for x in output_list]
|
| 46 |
-
# trigger_desc = ["dummy" for x in output_list]
|
| 47 |
-
# action = [x.split("<sep>")[3].strip() for x in output_list]
|
| 48 |
-
# action_desc = ["dummy" for x in output_list]
|
| 49 |
-
# df = {"Trigger": trigger,
|
| 50 |
-
# # "Trigger Description": trigger_desc,
|
| 51 |
-
# "Action": action,
|
| 52 |
-
# # "Action Description": action_desc
|
| 53 |
-
# }
|
| 54 |
return pd.DataFrame(df)
|
| 55 |
|
|
|
|
| 56 |
demo = gr.Blocks()
|
| 57 |
with demo:
|
| 58 |
gr.Markdown("<h1><center>RecipeGen: Automated TAPs Generation Tool</center></h1>")
|
|
@@ -69,24 +102,27 @@ with demo:
|
|
| 69 |
with gr.Tabs():
|
| 70 |
with gr.TabItem("Channel/Function"):
|
| 71 |
with gr.Column():
|
| 72 |
-
|
| 73 |
desc = gr.Textbox(label="Functionality Description", placeholder="Describe the functionality here")
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
# with gr.Row():
|
| 77 |
generate = gr.Button("Generate")
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
results = gr.Dataframe(headers=["Trigger", "Trigger Description", "Action", "Action Description"])
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
| 90 |
|
| 91 |
-
generate.click(generate_preds, inputs=[desc], outputs=[results])
|
|
|
|
| 92 |
demo.launch()
|
|
|
|
| 7 |
model = EncoderDecoderModel.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c_fc")
|
| 8 |
tokenizer = RobertaTokenizer.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c_fc")
|
| 9 |
|
| 10 |
+
def generate_preds(desc, gen_mode, num_beams, num_returned_seqs):
|
| 11 |
+
desc = desc.lower()
|
| 12 |
+
if gen_mode=="Channel":
|
| 13 |
+
desc = "GENERATE TRIGGER AND ACTION CHANNEL ONLY <pf> " + desc
|
| 14 |
+
elif gen_mode=="Function":
|
| 15 |
+
desc = "GENERATE BOTH CHANNEL AND FUNCTION FOR TRIGGER AND ACTION <pf> " + desc
|
|
|
|
|
|
|
| 16 |
|
| 17 |
input_ids = tokenizer.encode(desc, return_tensors='pt')
|
| 18 |
|
|
|
|
| 20 |
preds = model.generate(
|
| 21 |
input_ids,
|
| 22 |
max_length=100,
|
| 23 |
+
num_beams=num_beams,
|
| 24 |
+
num_return_sequences=num_returned_seqs,
|
| 25 |
+
early_stopping=True
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
output_list = []
|
| 29 |
+
for item in preds:
|
| 30 |
+
output_list.append(tokenizer.decode(item, skip_special_tokens=True))
|
| 31 |
+
|
| 32 |
+
if gen_mode=="Channel":
|
| 33 |
+
trigger = [x.split("<sep>")[0].strip() for x in output_list]
|
| 34 |
+
trigger_desc = ["dummy" for x in output_list]
|
| 35 |
+
action = [x.split("<sep>")[1].strip() for x in output_list]
|
| 36 |
+
action_desc = ["dummy" for x in output_list]
|
| 37 |
+
df = {"Trigger": trigger,
|
| 38 |
+
"Trigger Description": trigger_desc,
|
| 39 |
+
"Action": action,
|
| 40 |
+
"Action Description": action_desc
|
| 41 |
+
}
|
| 42 |
+
elif gen_mode=="Function":
|
| 43 |
+
trigger = [x.split("<sep>")[1].strip() for x in output_list]
|
| 44 |
+
trigger_desc = ["dummy" for x in output_list]
|
| 45 |
+
action = [x.split("<sep>")[3].strip() for x in output_list]
|
| 46 |
+
action_desc = ["dummy" for x in output_list]
|
| 47 |
+
df = {"Trigger": trigger,
|
| 48 |
+
"Trigger Description": trigger_desc,
|
| 49 |
+
"Action": action,
|
| 50 |
+
"Action Description": action_desc
|
| 51 |
+
}
|
| 52 |
+
return pd.DataFrame(df)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def generate_preds_field(desc_field, num_beams_field, num_returned_seqs_field):
|
| 56 |
+
desc_field = desc_field.lower()
|
| 57 |
+
|
| 58 |
+
input_ids = tokenizer.encode(desc_field, return_tensors='pt')
|
| 59 |
+
|
| 60 |
+
# activate beam search and early_stopping
|
| 61 |
+
preds = model.generate(
|
| 62 |
+
input_ids,
|
| 63 |
+
max_length=100,
|
| 64 |
+
num_beams=num_beams_field,
|
| 65 |
+
num_return_sequences=num_returned_seqs_field,
|
| 66 |
early_stopping=True
|
| 67 |
)
|
| 68 |
|
|
|
|
| 70 |
for item in preds:
|
| 71 |
output_list.append(tokenizer.decode(item, skip_special_tokens=True))
|
| 72 |
|
|
|
|
| 73 |
trigger = [x.split("<sep>")[0].strip() for x in output_list]
|
| 74 |
+
trigger_desc = ["dummy" for x in output_list]
|
| 75 |
+
trigger_fields = ["dummy" for x in output_list]
|
| 76 |
action = [x.split("<sep>")[1].strip() for x in output_list]
|
| 77 |
+
action_desc = ["dummy" for x in output_list]
|
| 78 |
+
action_fields = ["dummy" for x in output_list]
|
| 79 |
df = {"Trigger": trigger,
|
| 80 |
+
"Trigger Description": trigger_desc,
|
| 81 |
+
"Trigger Fields": trigger_fields,
|
| 82 |
"Action": action,
|
| 83 |
+
"Action Description": action_desc,
|
| 84 |
+
"Action Fields": action_fields
|
| 85 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
return pd.DataFrame(df)
|
| 87 |
|
| 88 |
+
|
| 89 |
demo = gr.Blocks()
|
| 90 |
with demo:
|
| 91 |
gr.Markdown("<h1><center>RecipeGen: Automated TAPs Generation Tool</center></h1>")
|
|
|
|
| 102 |
with gr.Tabs():
|
| 103 |
with gr.TabItem("Channel/Function"):
|
| 104 |
with gr.Column():
|
| 105 |
+
gen_mode = gr.Radio(label="Granularity", choices=["Channel", "Function"])
|
| 106 |
desc = gr.Textbox(label="Functionality Description", placeholder="Describe the functionality here")
|
| 107 |
+
num_beams = gr.Slider(minimum=2, maximum=500, value=10, step=1, label="Beam Width")
|
| 108 |
+
num_returned_seqs = gr.Slider(minimum=2, maximum=500, value=10, step=1, label="#Returned Sequences")
|
|
|
|
| 109 |
generate = gr.Button("Generate")
|
| 110 |
+
|
| 111 |
+
with gr.Box():
|
| 112 |
+
gr.Markdown("<h1><center>Results</center></h1>")
|
| 113 |
results = gr.Dataframe(headers=["Trigger", "Trigger Description", "Action", "Action Description"])
|
| 114 |
|
| 115 |
+
with gr.TabItem("Field"):
|
| 116 |
+
with gr.Column():
|
| 117 |
+
desc_field = gr.Textbox(label="Functionality Description", placeholder="Describe the functionality here")
|
| 118 |
+
num_beams_field = gr.Slider(minimum=2, maximum=500, value=10, step=1, label="Beam Width")
|
| 119 |
+
num_returned_seqs_field = gr.Slider(minimum=2, maximum=500, value=10, step=1, label="#Returned Sequences")
|
| 120 |
+
generate_field = gr.Button("Generate")
|
| 121 |
+
|
| 122 |
+
with gr.Box():
|
| 123 |
+
gr.Markdown("<h1><center>Results</center></h1>")
|
| 124 |
+
results_field = gr.Dataframe(headers=["Trigger", "Trigger Description", "Trigger Fields", "Action", "Action Description", "Action Fields"])
|
| 125 |
|
| 126 |
+
generate.click(generate_preds, inputs=[desc, gen_mode, num_beams, num_returned_seqs], outputs=[results])
|
| 127 |
+
generate_field.click(generate_preds_field, inputs=[desc_field, num_beams_field, num_returned_seqs_field], outputs=[results_field])
|
| 128 |
demo.launch()
|