Spaces:
Runtime error
Runtime error
John Yang
commited on
Commit
·
c6b2f05
1
Parent(s):
5d16b15
Add `env` input
Browse files
app.py
CHANGED
@@ -13,13 +13,17 @@ from predict_help import (
|
|
13 |
|
14 |
ENVIRONMENTS = ['amazon', 'webshop', 'ebay']
|
15 |
|
|
|
|
|
|
|
|
|
16 |
# load IL models
|
17 |
bart_tokenizer = BartTokenizer.from_pretrained('facebook/bart-large')
|
18 |
bart_model = BartForConditionalGeneration.from_pretrained('webshop/il_search_bart')
|
19 |
|
20 |
bert_tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased', truncation_side='left')
|
21 |
bert_tokenizer.add_tokens(['[button]', '[button_]', '[clicked button]', '[clicked button_]'], special_tokens=True)
|
22 |
-
bert_model = AutoModel.from_pretrained(
|
23 |
|
24 |
def process_str(s):
|
25 |
s = s.lower().replace('"', '').replace("'", "").strip()
|
@@ -98,12 +102,13 @@ def predict(obs, info):
|
|
98 |
else:
|
99 |
return "search[" + bart_predict(process_goal(obs)) + "]"
|
100 |
|
101 |
-
def run_episode(goal, verbose=True
|
102 |
"""
|
103 |
Interact with amazon to find a product given input goal.
|
104 |
Input: text goal
|
105 |
Output: a url of found item on amazon.
|
106 |
"""
|
|
|
107 |
if env not in ENVIRONMENTS:
|
108 |
print(f"[ERROR] Environment {env} not recognized")
|
109 |
|
@@ -289,14 +294,17 @@ def run_episode(goal, verbose=True, env='amazon'):
|
|
289 |
return return_value
|
290 |
|
291 |
gr.Interface(fn=run_episode,\
|
292 |
-
inputs=
|
|
|
|
|
|
|
293 |
outputs="text",\
|
294 |
examples=[
|
295 |
-
"Please select a 1 pound, certified organic sea salt shaker in the flavor triple blend flakes, and price lower than 40.00 dollars",
|
296 |
-
"I want to find a gold floor lamp with a glass shade and a nickel finish that i can use for my living room, and price lower than 270.00 dollars",
|
297 |
-
"I'm trying to find white bluetooth speakers that are not only water resistant but also come with stereo sound",
|
298 |
-
"I
|
299 |
-
"I
|
300 |
],\
|
301 |
title="WebShop",\
|
302 |
article="<p style='padding-top:15px;text-align:center;'>To learn more about this project, check out the <a href='https://webshop-pnlp.github.io/' target='_blank'>project page</a>!</p>",\
|
|
|
13 |
|
14 |
ENVIRONMENTS = ['amazon', 'webshop', 'ebay']
|
15 |
|
16 |
+
# IL+RL: 'webshop/il-rl-choice-bert-image_1'
|
17 |
+
# IL: 'webshop/il-choice-bert-image_0'
|
18 |
+
BERT_MODEL_PATH = 'webshop/il-choice-bert-image_0'
|
19 |
+
|
20 |
# load IL models
|
21 |
bart_tokenizer = BartTokenizer.from_pretrained('facebook/bart-large')
|
22 |
bart_model = BartForConditionalGeneration.from_pretrained('webshop/il_search_bart')
|
23 |
|
24 |
bert_tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased', truncation_side='left')
|
25 |
bert_tokenizer.add_tokens(['[button]', '[button_]', '[clicked button]', '[clicked button_]'], special_tokens=True)
|
26 |
+
bert_model = AutoModel.from_pretrained(BERT_MODEL_PATH, trust_remote_code=True)
|
27 |
|
28 |
def process_str(s):
|
29 |
s = s.lower().replace('"', '').replace("'", "").strip()
|
|
|
102 |
else:
|
103 |
return "search[" + bart_predict(process_goal(obs)) + "]"
|
104 |
|
105 |
+
def run_episode(goal, env, verbose=True):
|
106 |
"""
|
107 |
Interact with amazon to find a product given input goal.
|
108 |
Input: text goal
|
109 |
Output: a url of found item on amazon.
|
110 |
"""
|
111 |
+
env = env.lower()
|
112 |
if env not in ENVIRONMENTS:
|
113 |
print(f"[ERROR] Environment {env} not recognized")
|
114 |
|
|
|
294 |
return return_value
|
295 |
|
296 |
gr.Interface(fn=run_episode,\
|
297 |
+
inputs=[
|
298 |
+
gr.inputs.Textbox(lines=7, label="Input Text"),
|
299 |
+
gr.inputs.Radio(['Amazon', 'eBay', 'WebShop'], type="value", default="Amazon", label='Environment')
|
300 |
+
],\
|
301 |
outputs="text",\
|
302 |
examples=[
|
303 |
+
["Please select a 1 pound, certified organic sea salt shaker in the flavor triple blend flakes, and price lower than 40.00 dollars", "Amazon"],
|
304 |
+
["I want to find a gold floor lamp with a glass shade and a nickel finish that i can use for my living room, and price lower than 270.00 dollars", "Amazon"],
|
305 |
+
["I'm trying to find white bluetooth speakers that are not only water resistant but also come with stereo sound", "Amazon"],
|
306 |
+
["I need some cute heart-shaped glittery cupcake picks as a gift to bring to a baby shower", "eBay"],
|
307 |
+
["I'm looking for a kids toothbrush for ages 6 to 12 that will help with teeth whitening and is easy to use", "WebShop"],
|
308 |
],\
|
309 |
title="WebShop",\
|
310 |
article="<p style='padding-top:15px;text-align:center;'>To learn more about this project, check out the <a href='https://webshop-pnlp.github.io/' target='_blank'>project page</a>!</p>",\
|