phyloforfun commited on
Commit
2e76bd4
1 Parent(s): 82babfb

file upload gallery

Browse files
Files changed (1) hide show
  1. app.py +55 -15
app.py CHANGED
@@ -20,7 +20,7 @@ from vouchervision.vouchervision_main import voucher_vision, voucher_vision_OCR_
20
  from vouchervision.general_utils import test_GPU, get_cfg_from_full_path, summarize_expense_report, create_google_ocr_yaml_config, validate_dir
21
 
22
  PROMPTS_THAT_NEED_DOMAIN_KNOWLEDGE = ["Version 1","Version 1 PaLM 2"]
23
- LLM_VERSIONS = ["GPT 4", "GPT 3.5", "Azure GPT 4", "Azure GPT 3.5", "PaLM 2"]
24
  COLORS_EXPENSE_REPORT = {
25
  'GPT_4': '#8fff66', # Bright Green
26
  'GPT_3_5': '#006400', # Dark Green
@@ -609,23 +609,30 @@ def image_to_base64(img):
609
  # st.markdown(css, unsafe_allow_html=True)
610
 
611
  def show_available_APIs():
612
- has_key_openai = bool(os.getenv('OPENAI_API_KEY')) is not None
613
- has_key_google_OCR = bool(os.getenv('GOOGLE_APPLICATION_CREDENTIALS')) is not None
614
- has_key_palm2 = bool(os.getenv('PALM_API_KEY')) is not None
615
- has_key_azure = bool(os.getenv('AZURE_API_KEY')) is not None
616
 
617
  emoji_good = ":heavy_check_mark:"
618
  emoji_bad = ":x:"
619
 
620
  table = {
621
- 'OpenAI API': emoji_good if has_key_openai else emoji_bad,
622
- 'Google OCR API': emoji_good if has_key_google_OCR else emoji_bad,
623
- 'Palm API': emoji_good if has_key_palm2 else emoji_bad,
624
- 'Azure API': emoji_good if has_key_azure else emoji_bad,
625
  }
626
  for api_name, status in table.items():
627
  st.markdown(f"* {status} {api_name}")
628
 
 
 
 
 
 
 
 
629
  def display_image_gallery():
630
  # Initialize the container
631
  con_image = st.empty()
@@ -1346,13 +1353,34 @@ def content_tab_settings():
1346
 
1347
  ### LLM Version
1348
  with col_project_2:
1349
- st.session_state.config['leafmachine']['project']['dir_images_local'] = st.session_state['dir_uploaded_images'] #st.text_input("Input images directory", st.session_state.config['leafmachine']['project'].get('dir_images_local', ''))
1350
- # st.session_state.config['leafmachine']['project']['continue_run_from_partial_xlsx'] = st.text_input("Continue run from partially completed project XLSX", st.session_state.config['leafmachine']['project'].get('continue_run_from_partial_xlsx', ''), disabled=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
1351
  st.subheader('LLM Version')
1352
- st.session_state.config['leafmachine']['LLM_version'] = st.selectbox("LLM version", LLM_VERSIONS,
1353
- index=LLM_VERSIONS.index(st.session_state.config['leafmachine'].get('LLM_version', 'Azure GPT 4')),
1354
- label_visibility='collapsed')
1355
- st.markdown("""***Note:*** GPT-4 is significantly more expensive than GPT-3.5 """)
 
 
 
 
 
 
 
 
1356
 
1357
  ### Prompt Version
1358
  with col_project_3:
@@ -1709,6 +1737,18 @@ if 'show_prompt_name_w' not in st.session_state:
1709
  st.session_state['show_prompt_name_w'] = None
1710
  if 'user_clicked_load_prompt_yaml' not in st.session_state:
1711
  st.session_state['user_clicked_load_prompt_yaml'] = None
 
 
 
 
 
 
 
 
 
 
 
 
1712
 
1713
 
1714
  # if not st.session_state.private_file:
 
20
  from vouchervision.general_utils import test_GPU, get_cfg_from_full_path, summarize_expense_report, create_google_ocr_yaml_config, validate_dir
21
 
22
  PROMPTS_THAT_NEED_DOMAIN_KNOWLEDGE = ["Version 1","Version 1 PaLM 2"]
23
+ # LLM_VERSIONS = ["GPT 4", "GPT 3.5", "Azure GPT 4", "Azure GPT 3.5", "PaLM 2"]
24
  COLORS_EXPENSE_REPORT = {
25
  'GPT_4': '#8fff66', # Bright Green
26
  'GPT_3_5': '#006400', # Dark Green
 
609
  # st.markdown(css, unsafe_allow_html=True)
610
 
611
  def show_available_APIs():
612
+ st.session_state['has_key_openai'] = os.getenv('OPENAI_API_KEY') is not None
613
+ st.session_state['has_key_google_OCR'] = os.getenv('GOOGLE_APPLICATION_CREDENTIALS') is not None
614
+ st.session_state['has_key_palm2'] = os.getenv('PALM_API_KEY') is not None
615
+ st.session_state['has_key_azure'] = os.getenv('AZURE_API_KEY') is not None
616
 
617
  emoji_good = ":heavy_check_mark:"
618
  emoji_bad = ":x:"
619
 
620
  table = {
621
+ 'Google OCR API': emoji_good if st.session_state['has_key_google_OCR'] else emoji_bad,
622
+ 'OpenAI API': emoji_good if st.session_state['has_key_openai'] else emoji_bad,
623
+ 'Palm API': emoji_good if st.session_state['has_key_palm2'] else emoji_bad,
624
+ 'Azure API': emoji_good if st.session_state['has_key_azure'] else emoji_bad,
625
  }
626
  for api_name, status in table.items():
627
  st.markdown(f"* {status} {api_name}")
628
 
629
+ # Define the available versions based on the API keys
630
+ st.session_state['LLM_VERSIONS'] = {
631
+ 'OpenAI API': ["GPT 4", "GPT 3.5"],
632
+ 'Azure API': ["Azure GPT 4", "Azure GPT 3.5"],
633
+ 'Palm API': ["PaLM 2"]
634
+ }
635
+
636
  def display_image_gallery():
637
  # Initialize the container
638
  con_image = st.empty()
 
1353
 
1354
  ### LLM Version
1355
  with col_project_2:
1356
+ # LLM_VERSIONS_available =
1357
+ # st.session_state.config['leafmachine']['project']['dir_images_local'] = st.session_state['dir_uploaded_images'] #st.text_input("Input images directory", st.session_state.config['leafmachine']['project'].get('dir_images_local', ''))
1358
+ # # st.session_state.config['leafmachine']['project']['continue_run_from_partial_xlsx'] = st.text_input("Continue run from partially completed project XLSX", st.session_state.config['leafmachine']['project'].get('continue_run_from_partial_xlsx', ''), disabled=True)
1359
+ # st.subheader('LLM Version')
1360
+ # st.session_state.config['leafmachine']['LLM_version'] = st.selectbox("LLM version", LLM_VERSIONS,
1361
+ # index=LLM_VERSIONS.index(st.session_state.config['leafmachine'].get('LLM_version', 'Azure GPT 4')),
1362
+ # label_visibility='collapsed')
1363
+ # st.markdown("""***Note:*** GPT-4 is significantly more expensive than GPT-3.5 """)
1364
+ # Now filter the LLM_VERSIONS based on the available API keys
1365
+ available_versions = []
1366
+ for api_name, versions in st.session_state['LLM_VERSIONS'].items():
1367
+ if st.session_state.get(f'has_key_{api_name.lower().replace(" ", "_")}', False):
1368
+ available_versions.extend(versions)
1369
+
1370
+ # Show available LLM versions in a select box
1371
  st.subheader('LLM Version')
1372
+ if available_versions:
1373
+ # Get current selection from session_state, defaulting to the first available version
1374
+ current_selection = st.session_state.config['leafmachine'].get('LLM_version', available_versions[0])
1375
+ # Update the selection with a selectbox
1376
+ st.session_state.config['leafmachine']['LLM_version'] = st.selectbox(
1377
+ "LLM version", available_versions,
1378
+ index=available_versions.index(current_selection),
1379
+ label_visibility='collapsed'
1380
+ )
1381
+ st.markdown("""***Note:*** GPT-4 is significantly more expensive than GPT-3.5""")
1382
+ else:
1383
+ st.error("No LLM versions are available due to missing API keys.")
1384
 
1385
  ### Prompt Version
1386
  with col_project_3:
 
1737
  st.session_state['show_prompt_name_w'] = None
1738
  if 'user_clicked_load_prompt_yaml' not in st.session_state:
1739
  st.session_state['user_clicked_load_prompt_yaml'] = None
1740
+
1741
+ if 'has_key_openai' not in st.session_state:
1742
+ st.session_state['has_key_openai'] = False
1743
+ if 'has_key_google_OCR' not in st.session_state:
1744
+ st.session_state['has_key_google_OCR'] = False
1745
+ if 'has_key_palm2' not in st.session_state:
1746
+ st.session_state['has_key_palm2'] = False
1747
+ if 'has_key_azure' not in st.session_state:
1748
+ st.session_state['has_key_azure'] = False
1749
+ if 'LLM_VERSIONS' not in st.session_state:
1750
+ st.session_state['LLM_VERSIONS'] = None
1751
+
1752
 
1753
 
1754
  # if not st.session_state.private_file: