Spaces:
Runtime error
Runtime error
Timothyxxx
commited on
Commit
·
9ca257b
1
Parent(s):
81f1d37
Fix
Browse files- app.py +8 -8
- resources/demo_description.md +4 -1
app.py
CHANGED
@@ -186,10 +186,10 @@ with col1:
|
|
186 |
"Select a programming language",
|
187 |
("SQL", "Python"),
|
188 |
)
|
189 |
-
if selected_language == 'SQL':
|
190 |
args.prompt_file = 'templates/prompts/prompt_wikitq_v3.txt'
|
191 |
args.generate_type = 'nsql'
|
192 |
-
elif selected_language == 'Python':
|
193 |
args.prompt_file = 'templates/prompts/prompt_wikitq_python_simplified_v4.txt'
|
194 |
args.generate_type = 'npython'
|
195 |
else:
|
@@ -212,13 +212,13 @@ with st.spinner("Generating Binder program to solve the question...will be finis
|
|
212 |
|
213 |
# Do execution
|
214 |
st.subheader("Binder program")
|
215 |
-
if selected_language == 'SQL':
|
216 |
st.markdown('```sql\n' + binder_program + '\n```')
|
217 |
# st.markdown('```' + binder_program + '```')
|
218 |
# with st.container():
|
219 |
# st.write(binder_program)
|
220 |
executor = NSQLExecutor(args, keys=keys)
|
221 |
-
elif selected_language == 'Python':
|
222 |
st.code(binder_program, language='python')
|
223 |
executor = NPythonExecutor(args, keys=keys)
|
224 |
db = db.get_table_df()
|
@@ -229,7 +229,7 @@ try:
|
|
229 |
os.makedirs('tmp_for_vis/', exist_ok=True)
|
230 |
with st.spinner("Executing... will be finished in 30s, please refresh the page if not"):
|
231 |
exec_answer = executor.nsql_exec(stamp, binder_program, db)
|
232 |
-
if selected_language == 'SQL':
|
233 |
with open("tmp_for_vis/{}_tmp_for_vis_steps.txt".format(stamp), "r") as f:
|
234 |
steps = json.load(f)
|
235 |
for i, step in enumerate(steps):
|
@@ -254,9 +254,9 @@ try:
|
|
254 |
st.markdown('$\\rightarrow$')
|
255 |
if i == len(steps) - 1:
|
256 |
# The final step
|
257 |
-
st.markdown("{} Interpreter".format(selected_language))
|
258 |
else:
|
259 |
-
st.markdown("Codex")
|
260 |
with st.spinner('...'):
|
261 |
time.sleep(1)
|
262 |
with open("tmp_for_vis/{}_result_step_{}.txt".format(stamp, i), "r") as f:
|
@@ -276,7 +276,7 @@ try:
|
|
276 |
st.markdown(result_in_this_step)
|
277 |
with st.spinner('...'):
|
278 |
time.sleep(1)
|
279 |
-
elif selected_language == 'Python':
|
280 |
pass
|
281 |
if isinstance(exec_answer, list) and len(exec_answer) == 1:
|
282 |
exec_answer = exec_answer[0]
|
|
|
186 |
"Select a programming language",
|
187 |
("SQL", "Python"),
|
188 |
)
|
189 |
+
if selected_language == 'Binder SQL':
|
190 |
args.prompt_file = 'templates/prompts/prompt_wikitq_v3.txt'
|
191 |
args.generate_type = 'nsql'
|
192 |
+
elif selected_language == 'Binder Python':
|
193 |
args.prompt_file = 'templates/prompts/prompt_wikitq_python_simplified_v4.txt'
|
194 |
args.generate_type = 'npython'
|
195 |
else:
|
|
|
212 |
|
213 |
# Do execution
|
214 |
st.subheader("Binder program")
|
215 |
+
if selected_language == 'Binder SQL':
|
216 |
st.markdown('```sql\n' + binder_program + '\n```')
|
217 |
# st.markdown('```' + binder_program + '```')
|
218 |
# with st.container():
|
219 |
# st.write(binder_program)
|
220 |
executor = NSQLExecutor(args, keys=keys)
|
221 |
+
elif selected_language == 'Binder Python':
|
222 |
st.code(binder_program, language='python')
|
223 |
executor = NPythonExecutor(args, keys=keys)
|
224 |
db = db.get_table_df()
|
|
|
229 |
os.makedirs('tmp_for_vis/', exist_ok=True)
|
230 |
with st.spinner("Executing... will be finished in 30s, please refresh the page if not"):
|
231 |
exec_answer = executor.nsql_exec(stamp, binder_program, db)
|
232 |
+
if selected_language == 'Binder SQL':
|
233 |
with open("tmp_for_vis/{}_tmp_for_vis_steps.txt".format(stamp), "r") as f:
|
234 |
steps = json.load(f)
|
235 |
for i, step in enumerate(steps):
|
|
|
254 |
st.markdown('$\\rightarrow$')
|
255 |
if i == len(steps) - 1:
|
256 |
# The final step
|
257 |
+
st.markdown("Execute {} Interpreter".format(selected_language))
|
258 |
else:
|
259 |
+
st.markdown("Prompt GPT3 Codex")
|
260 |
with st.spinner('...'):
|
261 |
time.sleep(1)
|
262 |
with open("tmp_for_vis/{}_result_step_{}.txt".format(stamp, i), "r") as f:
|
|
|
276 |
st.markdown(result_in_this_step)
|
277 |
with st.spinner('...'):
|
278 |
time.sleep(1)
|
279 |
+
elif selected_language == 'Binder Python':
|
280 |
pass
|
281 |
if isinstance(exec_answer, list) and len(exec_answer) == 1:
|
282 |
exec_answer = exec_answer[0]
|
resources/demo_description.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
This is an interactive demo of Binder based on GPT3 Codex.
|
2 |
You can input a question about the table (maybe requiring external knowledge/functionality), and a Binder program will be generated and executed to derive the output answer.
|
|
|
3 |
|
4 |
-
|
|
|
5 |
We are trying to make the demo faster and more robust, please let us know if you have any feedback!
|
|
|
|
1 |
This is an interactive demo of Binder based on GPT3 Codex.
|
2 |
You can input a question about the table (maybe requiring external knowledge/functionality), and a Binder program will be generated and executed to derive the output answer.
|
3 |
+
For more details, check out our [website](https://lm-code-binder.github.io/).
|
4 |
|
5 |
+
|
6 |
+
*Note:* 1) Codex has query limits for openai keys, thus it may be slow in generation/execution when (high) concurrent requests occur.
|
7 |
We are trying to make the demo faster and more robust, please let us know if you have any feedback!
|
8 |
+
2) This page is just for demonstration, so we generate fewer program for speeding up, please check the [paper](https://arxiv.org/abs/2210.02875) and [code](https://github.com/HKUNLP/Binder) on majority vote and weight bias better result.
|