Update app.py
Browse files
app.py
CHANGED
|
@@ -37,8 +37,12 @@ def convert_to_base64(pil_image):
|
|
| 37 |
def oai_key_isvalid(api_key):
|
| 38 |
"""Check if a given OpenAI key is valid"""
|
| 39 |
try:
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return True
|
| 43 |
except:
|
| 44 |
return False
|
|
@@ -60,8 +64,8 @@ st.markdown(
|
|
| 60 |
)
|
| 61 |
|
| 62 |
|
| 63 |
-
def instantiate_agent(model1, model2, file_path = '...', image_path ='...'):
|
| 64 |
-
ss.agent = TeLLAgent(
|
| 65 |
model1 = model1,
|
| 66 |
model2 = model2,
|
| 67 |
tools_model='gpt-4o-2024-11-20',
|
|
@@ -70,11 +74,7 @@ def instantiate_agent(model1, model2, file_path = '...', image_path ='...'):
|
|
| 70 |
image_path =image_path)
|
| 71 |
return ss.agent
|
| 72 |
|
| 73 |
-
instantiate_agent(model1 = 'gpt-4o-2024-11-20', model2 = 'gpt-4o-2024-11-20')
|
| 74 |
-
tools = ss.agent.agent_executor2.tools
|
| 75 |
|
| 76 |
-
tool_list = pd.Series( {f"✅ {t.name}": t.description for t in tools}).reset_index()
|
| 77 |
-
tool_list.columns = ['Tool', 'Description']
|
| 78 |
|
| 79 |
def on_api_key_change():
|
| 80 |
api_key = ss.get('api_key') or os.getenv('OPENAI_API_KEY')
|
|
@@ -84,7 +84,10 @@ def on_api_key_change():
|
|
| 84 |
st.write("Please input a valid OpenAI API key.")
|
| 85 |
|
| 86 |
def run_prompt(prompt, file_path = '...', image_path = '...'):
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
st.chat_message("user").write(prompt)
|
| 89 |
with st.chat_message("assistant") :
|
| 90 |
try:
|
|
@@ -107,7 +110,7 @@ def run_prompt(prompt, file_path = '...', image_path = '...'):
|
|
| 107 |
|
| 108 |
|
| 109 |
pre_prompts = [
|
| 110 |
-
'
|
| 111 |
('The history and development of Y6'
|
| 112 |
|
| 113 |
),
|
|
@@ -133,30 +136,30 @@ with st.sidebar:
|
|
| 133 |
st.text_input(
|
| 134 |
'Input base url (optional).',
|
| 135 |
placeholder = 'Input base url (optional)',
|
| 136 |
-
key='base_url',
|
| 137 |
label_visibility="collapsed"
|
| 138 |
)
|
| 139 |
# Input model to use
|
| 140 |
-
st.
|
| 141 |
-
'
|
| 142 |
-
|
| 143 |
key='model1_select',
|
| 144 |
)
|
| 145 |
-
st.
|
| 146 |
-
'
|
| 147 |
-
|
| 148 |
key='model2_select',
|
| 149 |
)
|
| 150 |
st.text_input(
|
| 151 |
'Input SERP API KEY (optional).',
|
| 152 |
placeholder = 'Input SERP API KEY (optional)',
|
| 153 |
-
key='serp_api',
|
| 154 |
label_visibility="collapsed"
|
| 155 |
)
|
| 156 |
st.text_input(
|
| 157 |
'Input SEMANTIC SCHOLAR API KEY (optional).',
|
| 158 |
placeholder = 'Input SEMANTIC SCHOLAR API KEY (optional)',
|
| 159 |
-
key='semantic_scholar_url',
|
| 160 |
label_visibility="collapsed"
|
| 161 |
)
|
| 162 |
os.environ['OPENAI_API_KEY'] = ss.get('api_key')
|
|
@@ -170,7 +173,7 @@ with st.sidebar:
|
|
| 170 |
cols = st.columns(2)
|
| 171 |
with cols[0]:
|
| 172 |
st.button(
|
| 173 |
-
r'👑
|
| 174 |
on_click=lambda: run_prompt(pre_prompts[0]),
|
| 175 |
)
|
| 176 |
st.button(
|
|
@@ -199,8 +202,19 @@ with st.sidebar:
|
|
| 199 |
uploaded_file = st.file_uploader("Choose a PDF file")
|
| 200 |
if ss.get('file_type') == 'CSV (.csv)':
|
| 201 |
uploaded_file = st.file_uploader("Choose a csv file", type = 'csv')
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
| 203 |
# Display available tools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
st.markdown(f"# {len(tool_list)} available tools")
|
| 205 |
st.dataframe(
|
| 206 |
tool_list,
|
|
|
|
| 37 |
def oai_key_isvalid(api_key):
|
| 38 |
"""Check if a given OpenAI key is valid"""
|
| 39 |
try:
|
| 40 |
+
if os.getenv("OPENAI_API_BASE"):
|
| 41 |
+
llm = ChatOpenAI(openai_api_key = api_key, base_url=os.getenv("OPENAI_API_BASE"))
|
| 42 |
+
out = llm.invoke("This is a test")
|
| 43 |
+
else:
|
| 44 |
+
llm = ChatOpenAI(openai_api_key = api_key)
|
| 45 |
+
out = llm.invoke("This is a test")
|
| 46 |
return True
|
| 47 |
except:
|
| 48 |
return False
|
|
|
|
| 64 |
)
|
| 65 |
|
| 66 |
|
| 67 |
+
def instantiate_agent(model1, model2, file_path = '...', image_path ='...', tools=None):
|
| 68 |
+
ss.agent = TeLLAgent( tools=tools,
|
| 69 |
model1 = model1,
|
| 70 |
model2 = model2,
|
| 71 |
tools_model='gpt-4o-2024-11-20',
|
|
|
|
| 74 |
image_path =image_path)
|
| 75 |
return ss.agent
|
| 76 |
|
|
|
|
|
|
|
| 77 |
|
|
|
|
|
|
|
| 78 |
|
| 79 |
def on_api_key_change():
|
| 80 |
api_key = ss.get('api_key') or os.getenv('OPENAI_API_KEY')
|
|
|
|
| 84 |
st.write("Please input a valid OpenAI API key.")
|
| 85 |
|
| 86 |
def run_prompt(prompt, file_path = '...', image_path = '...'):
|
| 87 |
+
if ss.get('domain') =='Drug discovery':
|
| 88 |
+
agent = instantiate_agent(model1 = ss.get('model1_select'), model2 = ss.get('model2_select'), file_path = file_path, image_path =image_path, tools = 'drug')
|
| 89 |
+
else:
|
| 90 |
+
agent = instantiate_agent(model1 = ss.get('model1_select'), model2 = ss.get('model2_select'), file_path = file_path, image_path =image_path)
|
| 91 |
st.chat_message("user").write(prompt)
|
| 92 |
with st.chat_message("assistant") :
|
| 93 |
try:
|
|
|
|
| 110 |
|
| 111 |
|
| 112 |
pre_prompts = [
|
| 113 |
+
'Generate a donor with PCE = 10% ',
|
| 114 |
('The history and development of Y6'
|
| 115 |
|
| 116 |
),
|
|
|
|
| 136 |
st.text_input(
|
| 137 |
'Input base url (optional).',
|
| 138 |
placeholder = 'Input base url (optional)',
|
| 139 |
+
key='base_url',type='password',
|
| 140 |
label_visibility="collapsed"
|
| 141 |
)
|
| 142 |
# Input model to use
|
| 143 |
+
st.text_input(
|
| 144 |
+
'Input global planning model to use',
|
| 145 |
+
|
| 146 |
key='model1_select',
|
| 147 |
)
|
| 148 |
+
st.text_input(
|
| 149 |
+
'Input local execution model to use',
|
| 150 |
+
|
| 151 |
key='model2_select',
|
| 152 |
)
|
| 153 |
st.text_input(
|
| 154 |
'Input SERP API KEY (optional).',
|
| 155 |
placeholder = 'Input SERP API KEY (optional)',
|
| 156 |
+
key='serp_api',type='password',
|
| 157 |
label_visibility="collapsed"
|
| 158 |
)
|
| 159 |
st.text_input(
|
| 160 |
'Input SEMANTIC SCHOLAR API KEY (optional).',
|
| 161 |
placeholder = 'Input SEMANTIC SCHOLAR API KEY (optional)',
|
| 162 |
+
key='semantic_scholar_url',type='password',
|
| 163 |
label_visibility="collapsed"
|
| 164 |
)
|
| 165 |
os.environ['OPENAI_API_KEY'] = ss.get('api_key')
|
|
|
|
| 173 |
cols = st.columns(2)
|
| 174 |
with cols[0]:
|
| 175 |
st.button(
|
| 176 |
+
r'👑 Generate a donor with PCE = 10% 🧨 ',
|
| 177 |
on_click=lambda: run_prompt(pre_prompts[0]),
|
| 178 |
)
|
| 179 |
st.button(
|
|
|
|
| 202 |
uploaded_file = st.file_uploader("Choose a PDF file")
|
| 203 |
if ss.get('file_type') == 'CSV (.csv)':
|
| 204 |
uploaded_file = st.file_uploader("Choose a csv file", type = 'csv')
|
| 205 |
+
st.selectbox(
|
| 206 |
+
r'📚 Choose the domain ',
|
| 207 |
+
['Organic solar cell', 'Drug discovery'], key='domain',
|
| 208 |
+
)
|
| 209 |
# Display available tools
|
| 210 |
+
if ss.get('domain') == 'Drug discovery':
|
| 211 |
+
instantiate_agent(model1 = 'gpt-4o-2024-11-20', model2 = 'gpt-4o-2024-11-20' ,tools = 'drug')
|
| 212 |
+
else:
|
| 213 |
+
instantiate_agent(model1 = 'gpt-4o-2024-11-20', model2 = 'gpt-4o-2024-11-20' )
|
| 214 |
+
tools = ss.agent.agent_executor2.tools
|
| 215 |
+
|
| 216 |
+
tool_list = pd.Series( {f"✅ {t.name}": t.description for t in tools}).reset_index()
|
| 217 |
+
tool_list.columns = ['Tool', 'Description']
|
| 218 |
st.markdown(f"# {len(tool_list)} available tools")
|
| 219 |
st.dataframe(
|
| 220 |
tool_list,
|