Spaces:
Building
Building
doncamilom
commited on
Commit
•
453acb7
1
Parent(s):
9a29d94
add buttons with suggested prompts
Browse files- app.py +53 -15
- requirements.txt +2 -0
app.py
CHANGED
@@ -18,6 +18,7 @@ from dotenv import load_dotenv
|
|
18 |
|
19 |
load_dotenv()
|
20 |
ss = st.session_state
|
|
|
21 |
|
22 |
icon = Image.open('assets/logo0.png')
|
23 |
st.set_page_config(
|
@@ -59,6 +60,29 @@ def on_api_key_change():
|
|
59 |
if not oai_key_isvalid(api_key):
|
60 |
st.write("Please input a valid OpenAI API key.")
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
# sidebar
|
63 |
with st.sidebar:
|
64 |
chemcrow_logo = Image.open('assets/chemcrow-logo-bold-new.png')
|
@@ -74,28 +98,42 @@ with st.sidebar:
|
|
74 |
label_visibility="collapsed"
|
75 |
)
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# Display available tools
|
78 |
-
st.markdown(f"#
|
79 |
st.dataframe(
|
80 |
tool_list,
|
81 |
use_container_width=True,
|
82 |
hide_index=True,
|
83 |
-
height=
|
84 |
)
|
85 |
|
86 |
|
87 |
-
# Agent execution
|
88 |
-
if prompt := st.chat_input():
|
89 |
-
st.chat_message("user").write(prompt)
|
90 |
-
with st.chat_message("assistant"):
|
91 |
-
st_callback = StreamlitCallbackHandlerChem(
|
92 |
-
st.container(),
|
93 |
-
max_thought_containers = 4,
|
94 |
-
collapse_completed_thoughts = False,
|
95 |
-
output_placeholder=st.session_state
|
96 |
-
)
|
97 |
-
with wandb_tracing_enabled():
|
98 |
-
response = agent.run(prompt, callbacks=[st_callback])
|
99 |
-
st.write(response)
|
100 |
|
|
|
101 |
|
|
|
|
|
|
|
|
18 |
|
19 |
load_dotenv()
|
20 |
ss = st.session_state
|
21 |
+
ss.prompt = None
|
22 |
|
23 |
icon = Image.open('assets/logo0.png')
|
24 |
st.set_page_config(
|
|
|
60 |
if not oai_key_isvalid(api_key):
|
61 |
st.write("Please input a valid OpenAI API key.")
|
62 |
|
63 |
+
pre_prompts = [
|
64 |
+
'What is the molecular weight of sugar',
|
65 |
+
'Can I safely mix caffeine and sodium hydroxide?',
|
66 |
+
'How is safinamide synthesized?',
|
67 |
+
'How similar is morphine to heroin?'
|
68 |
+
]
|
69 |
+
|
70 |
+
|
71 |
+
def run_prompt(prompt):
|
72 |
+
|
73 |
+
st.chat_message("user").write(prompt)
|
74 |
+
with st.chat_message("assistant"):
|
75 |
+
st_callback = StreamlitCallbackHandlerChem(
|
76 |
+
st.container(),
|
77 |
+
max_thought_containers = 4,
|
78 |
+
collapse_completed_thoughts = False,
|
79 |
+
output_placeholder=ss
|
80 |
+
)
|
81 |
+
with wandb_tracing_enabled():
|
82 |
+
response = agent.run(prompt, callbacks=[st_callback])
|
83 |
+
st.write(response)
|
84 |
+
|
85 |
+
|
86 |
# sidebar
|
87 |
with st.sidebar:
|
88 |
chemcrow_logo = Image.open('assets/chemcrow-logo-bold-new.png')
|
|
|
98 |
label_visibility="collapsed"
|
99 |
)
|
100 |
|
101 |
+
# Display prompt examples
|
102 |
+
st.markdown('# What can I ask?')
|
103 |
+
cols = st.columns(2)
|
104 |
+
with cols[0]:
|
105 |
+
st.button(
|
106 |
+
pre_prompts[0],
|
107 |
+
on_click=lambda: run_prompt(pre_prompts[0]),
|
108 |
+
)
|
109 |
+
st.button(
|
110 |
+
pre_prompts[1],
|
111 |
+
on_click=lambda: run_prompt(pre_prompts[1]),
|
112 |
+
)
|
113 |
+
with cols[1]:
|
114 |
+
st.button(
|
115 |
+
pre_prompts[2],
|
116 |
+
on_click=lambda: run_prompt(pre_prompts[2]),
|
117 |
+
)
|
118 |
+
st.button(
|
119 |
+
pre_prompts[3],
|
120 |
+
on_click=lambda: run_prompt(pre_prompts[3]),
|
121 |
+
)
|
122 |
+
|
123 |
+
|
124 |
# Display available tools
|
125 |
+
st.markdown(f"# {len(tool_list)} available tools")
|
126 |
st.dataframe(
|
127 |
tool_list,
|
128 |
use_container_width=True,
|
129 |
hide_index=True,
|
130 |
+
height=200
|
131 |
)
|
132 |
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
prompt = None
|
136 |
|
137 |
+
# Determine the prompt to use
|
138 |
+
if user_input := st.chat_input():
|
139 |
+
run_prompt(user_input)
|
requirements.txt
CHANGED
@@ -8,3 +8,5 @@ wandb
|
|
8 |
chemcrow==0.3.11
|
9 |
pydantic==1.10.7
|
10 |
langchain==0.0.275
|
|
|
|
|
|
8 |
chemcrow==0.3.11
|
9 |
pydantic==1.10.7
|
10 |
langchain==0.0.275
|
11 |
+
typing-inspect==0.8.0
|
12 |
+
typing_extensions==4.5.0
|