Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,17 +9,17 @@ tokenizer = RobertaTokenizer.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c
|
|
| 9 |
|
| 10 |
from transformers import RobertaTokenizer, EncoderDecoderModel
|
| 11 |
import pandas as pd
|
| 12 |
-
def
|
| 13 |
-
input_desc = desc.lower()
|
| 14 |
-
if gen_mode=="Channel":
|
| 15 |
-
|
| 16 |
-
elif gen_mode=="Function":
|
| 17 |
-
|
| 18 |
|
| 19 |
model = EncoderDecoderModel.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c_fc")
|
| 20 |
tokenizer = RobertaTokenizer.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c_fc")
|
| 21 |
|
| 22 |
-
input_ids = tokenizer.encode(
|
| 23 |
|
| 24 |
# activate beam search and early_stopping
|
| 25 |
preds = model.generate(
|
|
@@ -34,30 +34,28 @@ def generate_taps(gen_mode, desc):
|
|
| 34 |
for item in preds:
|
| 35 |
output_list.append(tokenizer.decode(item, skip_special_tokens=True))
|
| 36 |
|
| 37 |
-
if gen_mode=="Channel":
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
elif gen_mode=="Function":
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
return pd.DataFrame(df)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
demo = gr.Blocks()
|
| 61 |
with demo:
|
| 62 |
gr.Markdown("<h1><center>RecipeGen: Automated TAPs Generation Tool</center></h1>")
|
| 63 |
gr.Markdown("<center>This demo allows you to generate TAPs (Trigger Action Programs) using functionality description described in English. You can learn the working detail of our tool from our paper<center>")
|
|
@@ -70,27 +68,27 @@ with demo:
|
|
| 70 |
5. Click **Generate**; the generated TAPs along with the description of each component will show in the **Results**
|
| 71 |
""")
|
| 72 |
gr.Markdown("NOTE: **#Returned Sequences** should be LESS THAN OR EQUAL **Beam Width**")
|
| 73 |
-
with gr.Tabs():
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
-
with gr.TabItem("Field"):
|
| 86 |
-
|
| 87 |
-
desc = gr.Textbox(label="Functionality Description", placeholder="Describe the functionality here")
|
| 88 |
-
num_beams = gr.Slider(minimum=2, maximum=500, value=2, step=1, label="Beam Width")
|
| 89 |
-
num_returned_seqs = gr.Slider(minimum=2, maximum=500, value=2, step=1, label="#Returned Sequences")
|
| 90 |
-
with gr.Row():
|
| 91 |
-
|
| 92 |
-
gr.Markdown("<h1><center>Results</center></h1>")
|
| 93 |
-
results_field = gr.Dataframe(headers=["Trigger", "Trigger Description", "Trigger Fields", "Action", "Action Description", "Action Fields"])
|
| 94 |
|
| 95 |
-
generate.click(
|
| 96 |
demo.launch()
|
|
|
|
| 9 |
|
| 10 |
from transformers import RobertaTokenizer, EncoderDecoderModel
|
| 11 |
import pandas as pd
|
| 12 |
+
def generate_preds(desc):
|
| 13 |
+
# input_desc = desc.lower()
|
| 14 |
+
# if gen_mode=="Channel":
|
| 15 |
+
# input_desc = "GENERATE TRIGGER AND ACTION CHANNEL ONLY <pf> " + input_desc
|
| 16 |
+
# elif gen_mode=="Function":
|
| 17 |
+
# input_desc = "GENERATE BOTH CHANNEL AND FUNCTION FOR TRIGGER AND ACTION <pf> " + input_desc
|
| 18 |
|
| 19 |
model = EncoderDecoderModel.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c_fc")
|
| 20 |
tokenizer = RobertaTokenizer.from_pretrained("imamnurby/rob2rand_chen_w_prefix_c_fc")
|
| 21 |
|
| 22 |
+
input_ids = tokenizer.encode(desc, return_tensors='pt')
|
| 23 |
|
| 24 |
# activate beam search and early_stopping
|
| 25 |
preds = model.generate(
|
|
|
|
| 34 |
for item in preds:
|
| 35 |
output_list.append(tokenizer.decode(item, skip_special_tokens=True))
|
| 36 |
|
| 37 |
+
# if gen_mode=="Channel":
|
| 38 |
+
trigger = [x.split("<sep>")[0].strip() for x in output_list]
|
| 39 |
+
# trigger_desc = ["dummy" for x in output_list]
|
| 40 |
+
action = [x.split("<sep>")[1].strip() for x in output_list]
|
| 41 |
+
# action_desc = ["dummy" for x in output_list]
|
| 42 |
+
df = {"Trigger": trigger,
|
| 43 |
+
# "Trigger Description": trigger_desc,
|
| 44 |
+
"Action": action,
|
| 45 |
+
# "Action Description": action_desc
|
| 46 |
+
}
|
| 47 |
+
# elif gen_mode=="Function":
|
| 48 |
+
# trigger = [x.split("<sep>")[1].strip() for x in output_list]
|
| 49 |
+
# trigger_desc = ["dummy" for x in output_list]
|
| 50 |
+
# action = [x.split("<sep>")[3].strip() for x in output_list]
|
| 51 |
+
# action_desc = ["dummy" for x in output_list]
|
| 52 |
+
# df = {"Trigger": trigger,
|
| 53 |
+
# # "Trigger Description": trigger_desc,
|
| 54 |
+
# "Action": action,
|
| 55 |
+
# # "Action Description": action_desc
|
| 56 |
+
# }
|
| 57 |
return pd.DataFrame(df)
|
| 58 |
|
|
|
|
|
|
|
| 59 |
with demo:
|
| 60 |
gr.Markdown("<h1><center>RecipeGen: Automated TAPs Generation Tool</center></h1>")
|
| 61 |
gr.Markdown("<center>This demo allows you to generate TAPs (Trigger Action Programs) using functionality description described in English. You can learn the working detail of our tool from our paper<center>")
|
|
|
|
| 68 |
5. Click **Generate**; the generated TAPs along with the description of each component will show in the **Results**
|
| 69 |
""")
|
| 70 |
gr.Markdown("NOTE: **#Returned Sequences** should be LESS THAN OR EQUAL **Beam Width**")
|
| 71 |
+
# with gr.Tabs():
|
| 72 |
+
# with gr.TabItem("Channel/Function"):
|
| 73 |
+
# with gr.Column():
|
| 74 |
+
# gen_mode = gr.Radio(label="Granularity", choices=["Channel", "Function"])
|
| 75 |
+
desc = gr.Textbox(label="Functionality Description", placeholder="Describe the functionality here")
|
| 76 |
+
# num_beams = gr.Slider(minimum=2, maximum=500, value=2, step=1, label="Beam Width")
|
| 77 |
+
# num_returned_seqs = gr.Slider(minimum=2, maximum=500, value=2, step=1, label="#Returned Sequences")
|
| 78 |
+
# with gr.Row():
|
| 79 |
+
generate = gr.Button("Generate")
|
| 80 |
+
# gr.Markdown("<h1><center>Results</center></h1>")
|
| 81 |
+
results = gr.Dataframe(headers=["Trigger", "Trigger Description", "Action", "Action Description"])
|
| 82 |
|
| 83 |
+
# with gr.TabItem("Field"):
|
| 84 |
+
# with gr.Column():
|
| 85 |
+
# desc = gr.Textbox(label="Functionality Description", placeholder="Describe the functionality here")
|
| 86 |
+
# num_beams = gr.Slider(minimum=2, maximum=500, value=2, step=1, label="Beam Width")
|
| 87 |
+
# num_returned_seqs = gr.Slider(minimum=2, maximum=500, value=2, step=1, label="#Returned Sequences")
|
| 88 |
+
# with gr.Row():
|
| 89 |
+
# generate_field = gr.Button("Generate")
|
| 90 |
+
# gr.Markdown("<h1><center>Results</center></h1>")
|
| 91 |
+
# results_field = gr.Dataframe(headers=["Trigger", "Trigger Description", "Trigger Fields", "Action", "Action Description", "Action Fields"])
|
| 92 |
|
| 93 |
+
generate.click(generate_preds, inputs=[desc], outputs=[results])
|
| 94 |
demo.launch()
|