Spaces:
Paused
Paused
Commit
Β·
04eb2a2
1
Parent(s):
f7e31d3
update readme + cc ver
Browse files- README.md +3 -3
- app.py +25 -32
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: ChemCrow
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: 1.25.0
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
title: ChemCrow
|
| 3 |
+
emoji: π¦ββ¬
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: black
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: 1.25.0
|
| 8 |
app_file: app.py
|
app.py
CHANGED
|
@@ -13,7 +13,7 @@ from langchain.chat_models import ChatOpenAI
|
|
| 13 |
from PIL import Image
|
| 14 |
from rmrkl import ChatZeroShotAgent, RetryAgentExecutor
|
| 15 |
|
| 16 |
-
from chemcrow.agents import ChemCrow
|
| 17 |
from chemcrow.agents.prompts import (FORMAT_INSTRUCTIONS, QUESTION_PROMPT,
|
| 18 |
SUFFIX)
|
| 19 |
from chemcrow.frontend.streamlit_callback_handler import \
|
|
@@ -48,6 +48,18 @@ st.markdown(
|
|
| 48 |
# Session state
|
| 49 |
# st.session_state['molecule'] = "CCO"
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# sidebar
|
| 53 |
with st.sidebar:
|
|
@@ -59,33 +71,15 @@ with st.sidebar:
|
|
| 59 |
st.text_input('OpenAI API key', type='password', key='api_key', label_visibility="collapsed")
|
| 60 |
|
| 61 |
# Display available tools
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
#)
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
agent = ChemCrow(
|
| 73 |
-
#tools,
|
| 74 |
-
model='gpt-4',
|
| 75 |
-
temp=0.1,
|
| 76 |
-
api_key=ss.get('api_key')
|
| 77 |
-
).agent_executor
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
#tool_list = pd.Series(
|
| 81 |
-
# {f"β
{t.name}":t.description for t in tools}
|
| 82 |
-
#).reset_index()
|
| 83 |
-
#tool_list.columns = ['Tool', 'Description']
|
| 84 |
-
|
| 85 |
-
|
| 86 |
|
| 87 |
|
| 88 |
-
print(st.session_state)
|
| 89 |
# Agent execution
|
| 90 |
if prompt := st.chat_input():
|
| 91 |
st.chat_message("user").write(prompt)
|
|
@@ -96,11 +90,10 @@ if prompt := st.chat_input():
|
|
| 96 |
collapse_completed_thoughts = False,
|
| 97 |
output_placeholder=st.session_state
|
| 98 |
)
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
# st.write("Please input a valid OpenAI API key.")
|
| 105 |
|
| 106 |
|
|
|
|
| 13 |
from PIL import Image
|
| 14 |
from rmrkl import ChatZeroShotAgent, RetryAgentExecutor
|
| 15 |
|
| 16 |
+
from chemcrow.agents import ChemCrow, make_tools
|
| 17 |
from chemcrow.agents.prompts import (FORMAT_INSTRUCTIONS, QUESTION_PROMPT,
|
| 18 |
SUFFIX)
|
| 19 |
from chemcrow.frontend.streamlit_callback_handler import \
|
|
|
|
| 48 |
# Session state
|
| 49 |
# st.session_state['molecule'] = "CCO"
|
| 50 |
|
| 51 |
+
agent = ChemCrow(
|
| 52 |
+
model='gpt-4',
|
| 53 |
+
temp=0.1,
|
| 54 |
+
api_key=ss.get('api_key')
|
| 55 |
+
).agent_executor
|
| 56 |
+
|
| 57 |
+
tools = agent.tools
|
| 58 |
+
|
| 59 |
+
tool_list = pd.Series(
|
| 60 |
+
{f"β
{t.name}":t.description for t in tools}
|
| 61 |
+
).reset_index()
|
| 62 |
+
tool_list.columns = ['Tool', 'Description']
|
| 63 |
|
| 64 |
# sidebar
|
| 65 |
with st.sidebar:
|
|
|
|
| 71 |
st.text_input('OpenAI API key', type='password', key='api_key', label_visibility="collapsed")
|
| 72 |
|
| 73 |
# Display available tools
|
| 74 |
+
st.markdown(f"# Available tools: {len(tool_list)}")
|
| 75 |
+
st.dataframe(
|
| 76 |
+
tool_list,
|
| 77 |
+
use_container_width=True,
|
| 78 |
+
hide_index=True,
|
| 79 |
+
height=300
|
| 80 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
|
|
|
|
| 83 |
# Agent execution
|
| 84 |
if prompt := st.chat_input():
|
| 85 |
st.chat_message("user").write(prompt)
|
|
|
|
| 90 |
collapse_completed_thoughts = False,
|
| 91 |
output_placeholder=st.session_state
|
| 92 |
)
|
| 93 |
+
try:
|
| 94 |
+
response = agent.run(prompt, callbacks=[st_callback])
|
| 95 |
+
st.write(response)
|
| 96 |
+
except:
|
| 97 |
+
st.write("Please input a valid OpenAI API key.")
|
|
|
|
| 98 |
|
| 99 |
|
requirements.txt
CHANGED
|
@@ -2,5 +2,5 @@ ipython
|
|
| 2 |
paper-scraper @ git+https://github.com/blackadad/paper-scraper.git
|
| 3 |
streamlit
|
| 4 |
python-dotenv
|
| 5 |
-
chemcrow
|
| 6 |
|
|
|
|
| 2 |
paper-scraper @ git+https://github.com/blackadad/paper-scraper.git
|
| 3 |
streamlit
|
| 4 |
python-dotenv
|
| 5 |
+
chemcrow
|
| 6 |
|