jinysun commited on
Commit
3b0f61d
·
verified ·
1 Parent(s): aabfc97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -23
app.py CHANGED
@@ -1,4 +1,4 @@
1
-
2
  import os
3
  import asyncio
4
  # Init with fake key
@@ -51,7 +51,8 @@ def oai_key_isvalid(api_key):
51
  load_dotenv()
52
  ss = st.session_state
53
  ss.prompt = None
54
-
 
55
  # Set width of sidebar
56
  st.markdown(
57
  """
@@ -108,8 +109,7 @@ def run_prompt(prompt, file_path = '...', image_path = '...'):
108
  except openai.APIError:
109
  # Handle specific API errors here
110
  print("OpenAI API error, please try again!")
111
-
112
-
113
  pre_prompts = [
114
  'Generate a donor with PCE = 10% ',
115
  ('The history and development of Y6'
@@ -173,23 +173,18 @@ with st.sidebar:
173
  st.markdown('# What can I ask?')
174
  cols = st.columns(2)
175
  with cols[0]:
176
- st.button(
177
- r'👑 Generate a donor with PCE = 10% 🧨 ',
178
- on_click=lambda: run_prompt(pre_prompts[0]),
179
- )
180
- st.button(
181
- r'📚 The history and development of Y6 ',
182
- on_click=lambda: run_prompt(pre_prompts[1]),
183
- )
184
  with cols[1]:
185
- st.button(
186
- r"🎄Predict the LogP of PM6 ",
187
- on_click=lambda: run_prompt(pre_prompts[2]),
188
- )
189
- st.button(
190
- r'💎 Predict the PCE of Y6',
191
- on_click=lambda: run_prompt(pre_prompts[3]),
192
- )
193
 
194
  st.selectbox(
195
  'Select the file type ',
@@ -219,15 +214,27 @@ with st.sidebar:
219
  st.markdown(f"# {len(tool_list)} available tools")
220
  st.dataframe(
221
  tool_list,
222
- use_container_width=True,
223
  hide_index=True,
224
  height=200
225
  )
226
 
 
 
 
 
 
 
 
 
 
227
  # Execute agent on user input
228
  if prompt := st.chat_input("Say something and/or attach files"):
229
-
230
- if uploaded_file is not None:
 
 
 
231
  if ss.get('file_type') == 'CSV (.csv)':
232
  with tempfile.NamedTemporaryFile( suffix ='.csv' ,delete=False) as f:
233
  f.write(uploaded_file.read())
 
1
+
2
  import os
3
  import asyncio
4
  # Init with fake key
 
51
  load_dotenv()
52
  ss = st.session_state
53
  ss.prompt = None
54
+ if 'pending_prompt' not in st.session_state:
55
+ st.session_state.pending_prompt = None
56
  # Set width of sidebar
57
  st.markdown(
58
  """
 
109
  except openai.APIError:
110
  # Handle specific API errors here
111
  print("OpenAI API error, please try again!")
112
+
 
113
  pre_prompts = [
114
  'Generate a donor with PCE = 10% ',
115
  ('The history and development of Y6'
 
173
  st.markdown('# What can I ask?')
174
  cols = st.columns(2)
175
  with cols[0]:
176
+ if st.button(r'👑 Generate a donor with PCE = 10% 🧨 '):
177
+ st.session_state.pending_prompt = pre_prompts[0]
178
+
179
+ if st.button(r'📚 The history and development of Y6 '):
180
+ st.session_state.pending_prompt = pre_prompts[1]
181
+
 
 
182
  with cols[1]:
183
+ if st.button(r"🎄Predict the LogP of PM6 "):
184
+ st.session_state.pending_prompt = pre_prompts[2]
185
+
186
+ if st.button(r'💎 Predict the PCE of Y6'):
187
+ st.session_state.pending_prompt = pre_prompts[3]
 
 
 
188
 
189
  st.selectbox(
190
  'Select the file type ',
 
214
  st.markdown(f"# {len(tool_list)} available tools")
215
  st.dataframe(
216
  tool_list,
217
+ width='stretch',
218
  hide_index=True,
219
  height=200
220
  )
221
 
222
+ if st.session_state.pending_prompt is not None:
223
+ prompt_to_run = st.session_state.pending_prompt
224
+ st.session_state.pending_prompt = None
225
+
226
+ if not ss.get('model1_select') or not ss.get('model2_select'):
227
+ st.error("⚠️ Please input both model names in the sidebar first!")
228
+ else:
229
+ run_prompt(prompt_to_run)
230
+
231
  # Execute agent on user input
232
  if prompt := st.chat_input("Say something and/or attach files"):
233
+
234
+ if not ss.get('model1_select') or not ss.get('model2_select'):
235
+ st.error("⚠️ Please input both model names in the sidebar first!")
236
+ elif uploaded_file is not None:
237
+
238
  if ss.get('file_type') == 'CSV (.csv)':
239
  with tempfile.NamedTemporaryFile( suffix ='.csv' ,delete=False) as f:
240
  f.write(uploaded_file.read())