phyloforfun commited on
Commit
c11017d
1 Parent(s): 2d052ae

update api prices, openai dev day

Browse files
Files changed (1) hide show
  1. app.py +243 -242
app.py CHANGED
@@ -278,260 +278,260 @@ def create_space_saver():
278
 
279
 
280
 
281
- def create_private_file():
282
- st.session_state.proceed_to_main = False
283
- st.title("VoucherVision")
284
- col_private, _ = st.columns([12, 2])
285
-
286
- openai_api_key = None
287
- azure_openai_api_version = None
288
- azure_openai_api_key = None
289
- azure_openai_api_base = None
290
- azure_openai_organization = None
291
- azure_openai_api_type = None
292
- google_vision = None
293
- google_palm = None
294
-
295
- # Fetch the environment variables or set to empty if not found
296
- env_variables = {
297
- 'OPENAI_API_KEY': os.getenv('OPENAI_API_KEY'),
298
- 'AZURE_API_VERSION': os.getenv('AZURE_API_VERSION'),
299
- 'AZURE_API_KEY': os.getenv('AZURE_API_KEY'),
300
- 'AZURE_API_BASE': os.getenv('AZURE_API_BASE'),
301
- 'AZURE_ORGANIZATION': os.getenv('AZURE_ORGANIZATION'),
302
- 'AZURE_API_TYPE': os.getenv('AZURE_API_TYPE'),
303
- 'AZURE_DEPLOYMENT_NAME': os.getenv('AZURE_DEPLOYMENT_NAME'),
304
- 'GOOGLE_APPLICATION_CREDENTIALS': os.getenv('GOOGLE_APPLICATION_CREDENTIALS'),
305
- 'PALM_API_KEY': os.getenv('PALM_API_KEY')
306
- }
307
-
308
- # Check if all environment variables are set
309
- all_env_set = all(value is not None for value in env_variables.values())
310
-
311
- with col_private:
312
- # Your existing UI code for showing the forms goes here
313
- st.header("Set API keys")
314
- st.info("***Note:*** There is a known bug with tabs in Streamlit. If you update an input field it may take you back to the 'Project Settings' tab. Changes that you made are saved, it's just an annoying glitch. We are aware of this issue and will fix it as soon as we can.")
315
- st.warning("To commit changes to API keys you must press the 'Set API Keys' button at the bottom of the page.")
316
- st.write("Before using VoucherVision you must set your API keys. All keys are stored locally on your computer and are never made public.")
317
- st.write("API keys are stored in `../VoucherVision/PRIVATE_DATA.yaml`.")
318
- st.write("Deleting this file will allow you to reset API keys. Alternatively, you can edit the keys in the user interface.")
319
- st.write("Leave keys blank if you do not intend to use that service.")
320
 
321
 
322
- if os.getenv('GOOGLE_APPLICATION_CREDENTIALS') is None:
323
- st.write("---")
324
- st.subheader("Google Vision (*Required*)")
325
- st.markdown("VoucherVision currently uses [Google Vision API](https://cloud.google.com/vision/docs/ocr) for OCR. Generating an API key for this is more involved than the others. [Please carefully follow the instructions outlined here to create and setup your account.](https://cloud.google.com/vision/docs/setup) ")
326
- st.markdown("""
327
- Once your account is created, [visit this page](https://console.cloud.google.com) and create a project. Then follow these instructions:
328
-
329
- - **Select your Project**: If you have multiple projects, ensure you select the one where you've enabled the Vision API.
330
- - **Open the Navigation Menu**: Click on the hamburger menu (three horizontal lines) in the top left corner.
331
- - **Go to IAM & Admin**: In the navigation pane, hover over "IAM & Admin" and then click on "Service accounts."
332
- - **Locate Your Service Account**: Find the service account for which you wish to download the JSON key. If you haven't created a service account yet, you'll need to do so by clicking the "CREATE SERVICE ACCOUNT" button at the top.
333
- - **Download the JSON Key**:
334
- - Click on the three dots (actions menu) on the right side of your service account name.
335
- - Select "Manage keys."
336
- - In the pop-up window, click on the "ADD KEY" button and select "JSON."
337
- - The JSON key file will automatically be downloaded to your computer.
338
- - **Store Safely**: This file contains sensitive data that can be used to authenticate and bill your Google Cloud account. Never commit it to public repositories or expose it in any way. Always keep it safe and secure.
339
- """)
340
- with st.container():
341
- c_in_ocr, c_button_ocr = st.columns([10,2])
342
- with c_in_ocr:
343
- google_vision = st.text_input(label = 'Full path to Google Cloud JSON API key file', value = '',
344
- placeholder = 'e.g. copy contents of file application_default_credentials.json',
345
- help ="This API Key is in the form of a JSON file. Please save the JSON file in a safe directory. DO NOT store the JSON key inside of the VoucherVision directory.",
346
- type='password',key='924857298734590283750932809238')
347
- st.secrets["db_username"]
348
- with c_button_ocr:
349
- st.empty()
350
 
351
- with st.container():
352
- with c_button_ocr:
353
- st.write("##")
354
- st.button("Test OCR", on_click=test_API, args=['google_vision',c_in_ocr,openai_api_key,azure_openai_api_version,azure_openai_api_key,
355
- azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
356
-
357
-
358
- if os.getenv('OPENAI_API_KEY') is None:
359
- st.write("---")
360
- st.subheader("OpenAI")
361
- st.markdown("API key for first-party OpenAI API. Create an account with OpenAI [here](https://platform.openai.com/signup), then create an API key [here](https://platform.openai.com/account/api-keys).")
362
- with st.container():
363
- c_in_openai, c_button_openai = st.columns([10,2])
364
- with c_in_openai:
365
- openai_api_key = st.text_input("openai_api_key", os.environ.get('OPENAI_API_KEY', ''),
366
- help='The actual API key. Likely to be a string of 2 character, a dash, and then a 48-character string: sk-XXXXXXXX...',
367
- placeholder = 'e.g. sk-XXXXXXXX...',
368
- type='password')
369
- with c_button_openai:
370
- st.empty()
371
- with st.container():
372
- with c_button_openai:
373
- st.write("##")
374
- st.button("Test OpenAI", on_click=test_API, args=['openai',c_in_openai,openai_api_key,azure_openai_api_version,azure_openai_api_key,
375
- azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
376
 
377
 
378
 
379
- if os.getenv('AZURE_API_KEY') is None:
380
- st.write("---")
381
- st.subheader("OpenAI - Azure")
382
- st.markdown("This version OpenAI relies on Azure servers directly as is intended for private enterprise instances of OpenAI's services, such as [UM-GPT](https://its.umich.edu/computing/ai). Administrators will provide you with the following information.")
383
- azure_openai_api_version = st.text_input("azure_openai_api_version", os.environ.get('AZURE_API_VERSION', ''),
384
- help='API Version e.g. "2023-05-15"',
385
- placeholder = 'e.g. 2023-05-15',
386
- type='password')
387
- azure_openai_api_key = st.text_input("azure_openai_api_key", os.environ.get('AZURE_API_KEY', ''),
388
- help='The actual API key. Likely to be a 32-character string',
389
- placeholder = 'e.g. 12333333333333333333333333333332',
390
- type='password')
391
- azure_openai_api_base = st.text_input("azure_openai_api_base", os.environ.get('AZURE_API_BASE', ''),
392
- help='The base url for the API e.g. "https://api.umgpt.umich.edu/azure-openai-api"',
393
- placeholder = 'e.g. https://api.umgpt.umich.edu/azure-openai-api',
394
- type='password')
395
- azure_openai_organization = st.text_input("azure_openai_organization", os.environ.get('AZURE_ORGANIZATION', ''),
396
- help='Your organization code. Likely a short string',
397
- placeholder = 'e.g. 123456',
398
- type='password')
399
- azure_openai_api_type = st.text_input("azure_openai_api_type", os.environ.get('AZURE_API_TYPE', ''),
400
- help='The API type. Typically "azure"',
401
- placeholder = 'e.g. azure',
402
- type='password')
403
- with st.container():
404
- c_in_azure, c_button_azure = st.columns([10,2])
405
- with c_button_azure:
406
- st.empty()
407
- with st.container():
408
- with c_button_azure:
409
- st.write("##")
410
- st.button("Test Azure OpenAI", on_click=test_API, args=['azure_openai',c_in_azure,openai_api_key,azure_openai_api_version,azure_openai_api_key,
411
- azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
412
 
413
 
414
 
415
- if os.getenv('PALM_API_KEY') is None:
416
- st.write("---")
417
- st.subheader("Google PaLM 2")
418
- st.markdown('Follow these [instructions](https://developers.generativeai.google/tutorials/setup) to generate an API key for PaLM 2. You may need to also activate an account with [MakerSuite](https://makersuite.google.com/app/apikey) and enable "early access."')
419
- with st.container():
420
- c_in_palm, c_button_palm = st.columns([10,2])
421
- with c_in_palm:
422
- google_palm = st.text_input("Google PaLM 2 API Key", os.environ.get('PALM_API_KEY', ''),
423
- help='The MakerSuite API key e.g. a 32-character string',
424
- placeholder='e.g. SATgthsykuE64FgrrrrEervr3S4455t_geyDeGq',
425
- type='password')
426
- with st.container():
427
- with c_button_palm:
428
- st.write("##")
429
- st.button("Test PaLM 2", on_click=test_API, args=['palm',c_in_palm,openai_api_key,azure_openai_api_version,azure_openai_api_key,
430
- azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
431
-
432
- st.button("Set API Keys",type='primary', on_click=set_API_keys, args=[openai_api_key,azure_openai_api_version,azure_openai_api_key,
433
- azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
434
-
435
- # # UI form for entering environment variables if not all are set
436
- # with st.form("env_variables"):
437
- # for var, value in env_variables.items():
438
- # env_variables[var] = st.text_input(f"Enter {var}", value or "")
439
- # submitted = st.form_submit_button("Submit")
440
- # if submitted:
441
- # # Assuming the environment variables should be set for the session
442
- # for var, value in env_variables.items():
443
- # os.environ[var] = value
444
- # st.success("Environment variables updated. Please restart your app.")
445
- if st.button('Proceed to VoucherVision'):
446
- st.session_state.proceed_to_private = False
447
- st.session_state.proceed_to_main = True
448
-
449
- def set_API_keys(openai_api_key, azure_openai_api_version, azure_openai_api_key, azure_openai_api_base, azure_openai_organization, azure_openai_api_type, google_vision, google_palm):
450
- # Set the environment variable if the key is not None or an empty string
451
- if openai_api_key:
452
- os.environ['OPENAI_API_KEY'] = openai_api_key
453
- if azure_openai_api_version:
454
- os.environ['AZURE_API_VERSION'] = azure_openai_api_version
455
- if azure_openai_api_key:
456
- os.environ['AZURE_API_KEY'] = azure_openai_api_key
457
- if azure_openai_api_base:
458
- os.environ['AZURE_API_BASE'] = azure_openai_api_base
459
- if azure_openai_organization:
460
- os.environ['AZURE_ORGANIZATION'] = azure_openai_organization
461
- if azure_openai_api_type:
462
- os.environ['AZURE_API_TYPE'] = azure_openai_api_type
463
- if google_vision:
464
- os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = google_vision
465
- if google_palm:
466
- os.environ['GOOGLE_PALM_API'] = google_palm
467
-
468
- st.success("API keys set successfully!")
469
 
470
 
471
- def test_API(api, message_loc,openai_api_key,azure_openai_api_version,azure_openai_api_key, azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm):
472
- # Save the API keys
473
- # save_changes_to_API_keys(openai_api_key,azure_openai_api_version,azure_openai_api_key,azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm)
474
- set_API_keys(openai_api_key, azure_openai_api_version, azure_openai_api_key,
475
- azure_openai_api_base, azure_openai_organization, azure_openai_api_type,
476
- google_vision, google_palm)
477
 
478
- with st.spinner('Performing validation checks...'):
479
- if api == 'google_vision':
480
- print("*** Google Vision OCR API Key ***")
481
- try:
482
- demo_config_path = os.path.join(st.session_state.dir_home,'demo','validation_configs','google_vision_ocr_test.yaml')
483
- demo_images_path = os.path.join(st.session_state.dir_home, 'demo', 'demo_images')
484
- demo_out_path = os.path.join(st.session_state.dir_home, 'demo', 'demo_output','run_name')
485
- create_google_ocr_yaml_config(demo_config_path, demo_images_path, demo_out_path)
486
- voucher_vision_OCR_test(demo_config_path, st.session_state.dir_home, None, demo_images_path)
487
- with message_loc:
488
- st.success("Google Vision OCR API Key Valid :white_check_mark:")
489
- return True
490
- except Exception as e:
491
- with message_loc:
492
- st.error(f"Google Vision OCR API Key Failed! {e}")
493
- return False
494
 
495
- elif api == 'openai':
496
- print("*** OpenAI API Key ***")
497
- try:
498
- if run_api_tests('openai'):
499
- with message_loc:
500
- st.success("OpenAI API Key Valid :white_check_mark:")
501
- else:
502
- with message_loc:
503
- st.error("OpenAI API Key Failed:exclamation:")
504
- return False
505
- except Exception as e:
506
- with message_loc:
507
- st.error(f"OpenAI API Key Failed:exclamation: {e}")
508
-
509
- elif api == 'azure_openai':
510
- print("*** Azure OpenAI API Key ***")
511
- try:
512
- if run_api_tests('azure_openai'):
513
- with message_loc:
514
- st.success("Azure OpenAI API Key Valid :white_check_mark:")
515
- else:
516
- with message_loc:
517
- st.error(f"Azure OpenAI API Key Failed:exclamation:")
518
- return False
519
- except Exception as e:
520
- with message_loc:
521
- st.error(f"Azure OpenAI API Key Failed:exclamation: {e}")
522
- elif api == 'palm':
523
- print("*** Google PaLM 2 API Key ***")
524
- try:
525
- if run_api_tests('palm'):
526
- with message_loc:
527
- st.success("Google PaLM 2 API Key Valid :white_check_mark:")
528
- else:
529
- with message_loc:
530
- st.error("Google PaLM 2 API Key Failed:exclamation:")
531
- return False
532
- except Exception as e:
533
- with message_loc:
534
- st.error(f"Google PaLM 2 API Key Failed:exclamation: {e}")
535
 
536
 
537
  def save_changes_to_API_keys(cfg_private,openai_api_key,azure_openai_api_version,azure_openai_api_key,
@@ -1371,6 +1371,7 @@ if 'zip_filepath' not in st.session_state:
1371
  if st.session_state.proceed_to_build_llm_prompt:
1372
  build_LLM_prompt_config()
1373
  elif st.session_state.proceed_to_private:
1374
- create_private_file()
 
1375
  elif st.session_state.proceed_to_main:
1376
  main()
 
278
 
279
 
280
 
281
+ # def create_private_file():
282
+ # st.session_state.proceed_to_main = False
283
+ # st.title("VoucherVision")
284
+ # col_private, _ = st.columns([12, 2])
285
+
286
+ # openai_api_key = None
287
+ # azure_openai_api_version = None
288
+ # azure_openai_api_key = None
289
+ # azure_openai_api_base = None
290
+ # azure_openai_organization = None
291
+ # azure_openai_api_type = None
292
+ # google_vision = None
293
+ # google_palm = None
294
+
295
+ # # Fetch the environment variables or set to empty if not found
296
+ # env_variables = {
297
+ # 'OPENAI_API_KEY': os.getenv('OPENAI_API_KEY'),
298
+ # 'AZURE_API_VERSION': os.getenv('AZURE_API_VERSION'),
299
+ # 'AZURE_API_KEY': os.getenv('AZURE_API_KEY'),
300
+ # 'AZURE_API_BASE': os.getenv('AZURE_API_BASE'),
301
+ # 'AZURE_ORGANIZATION': os.getenv('AZURE_ORGANIZATION'),
302
+ # 'AZURE_API_TYPE': os.getenv('AZURE_API_TYPE'),
303
+ # 'AZURE_DEPLOYMENT_NAME': os.getenv('AZURE_DEPLOYMENT_NAME'),
304
+ # 'GOOGLE_APPLICATION_CREDENTIALS': os.getenv('GOOGLE_APPLICATION_CREDENTIALS'),
305
+ # 'PALM_API_KEY': os.getenv('PALM_API_KEY')
306
+ # }
307
+
308
+ # # Check if all environment variables are set
309
+ # all_env_set = all(value is not None for value in env_variables.values())
310
+
311
+ # with col_private:
312
+ # # Your existing UI code for showing the forms goes here
313
+ # st.header("Set API keys")
314
+ # st.info("***Note:*** There is a known bug with tabs in Streamlit. If you update an input field it may take you back to the 'Project Settings' tab. Changes that you made are saved, it's just an annoying glitch. We are aware of this issue and will fix it as soon as we can.")
315
+ # st.warning("To commit changes to API keys you must press the 'Set API Keys' button at the bottom of the page.")
316
+ # st.write("Before using VoucherVision you must set your API keys. All keys are stored locally on your computer and are never made public.")
317
+ # st.write("API keys are stored in `../VoucherVision/PRIVATE_DATA.yaml`.")
318
+ # st.write("Deleting this file will allow you to reset API keys. Alternatively, you can edit the keys in the user interface.")
319
+ # st.write("Leave keys blank if you do not intend to use that service.")
320
 
321
 
322
+ # if os.getenv('GOOGLE_APPLICATION_CREDENTIALS') is None:
323
+ # st.write("---")
324
+ # st.subheader("Google Vision (*Required*)")
325
+ # st.markdown("VoucherVision currently uses [Google Vision API](https://cloud.google.com/vision/docs/ocr) for OCR. Generating an API key for this is more involved than the others. [Please carefully follow the instructions outlined here to create and setup your account.](https://cloud.google.com/vision/docs/setup) ")
326
+ # st.markdown("""
327
+ # Once your account is created, [visit this page](https://console.cloud.google.com) and create a project. Then follow these instructions:
328
+
329
+ # - **Select your Project**: If you have multiple projects, ensure you select the one where you've enabled the Vision API.
330
+ # - **Open the Navigation Menu**: Click on the hamburger menu (three horizontal lines) in the top left corner.
331
+ # - **Go to IAM & Admin**: In the navigation pane, hover over "IAM & Admin" and then click on "Service accounts."
332
+ # - **Locate Your Service Account**: Find the service account for which you wish to download the JSON key. If you haven't created a service account yet, you'll need to do so by clicking the "CREATE SERVICE ACCOUNT" button at the top.
333
+ # - **Download the JSON Key**:
334
+ # - Click on the three dots (actions menu) on the right side of your service account name.
335
+ # - Select "Manage keys."
336
+ # - In the pop-up window, click on the "ADD KEY" button and select "JSON."
337
+ # - The JSON key file will automatically be downloaded to your computer.
338
+ # - **Store Safely**: This file contains sensitive data that can be used to authenticate and bill your Google Cloud account. Never commit it to public repositories or expose it in any way. Always keep it safe and secure.
339
+ # """)
340
+ # with st.container():
341
+ # c_in_ocr, c_button_ocr = st.columns([10,2])
342
+ # with c_in_ocr:
343
+ # google_vision = st.text_input(label = 'Full path to Google Cloud JSON API key file', value = '',
344
+ # placeholder = 'e.g. copy contents of file application_default_credentials.json',
345
+ # help ="This API Key is in the form of a JSON file. Please save the JSON file in a safe directory. DO NOT store the JSON key inside of the VoucherVision directory.",
346
+ # type='password',key='924857298734590283750932809238')
347
+ # st.secrets["db_username"]
348
+ # with c_button_ocr:
349
+ # st.empty()
350
 
351
+ # with st.container():
352
+ # with c_button_ocr:
353
+ # st.write("##")
354
+ # st.button("Test OCR", on_click=test_API, args=['google_vision',c_in_ocr,openai_api_key,azure_openai_api_version,azure_openai_api_key,
355
+ # azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
356
+
357
+
358
+ # if os.getenv('OPENAI_API_KEY') is None:
359
+ # st.write("---")
360
+ # st.subheader("OpenAI")
361
+ # st.markdown("API key for first-party OpenAI API. Create an account with OpenAI [here](https://platform.openai.com/signup), then create an API key [here](https://platform.openai.com/account/api-keys).")
362
+ # with st.container():
363
+ # c_in_openai, c_button_openai = st.columns([10,2])
364
+ # with c_in_openai:
365
+ # openai_api_key = st.text_input("openai_api_key", os.environ.get('OPENAI_API_KEY', ''),
366
+ # help='The actual API key. Likely to be a string of 2 character, a dash, and then a 48-character string: sk-XXXXXXXX...',
367
+ # placeholder = 'e.g. sk-XXXXXXXX...',
368
+ # type='password')
369
+ # with c_button_openai:
370
+ # st.empty()
371
+ # with st.container():
372
+ # with c_button_openai:
373
+ # st.write("##")
374
+ # st.button("Test OpenAI", on_click=test_API, args=['openai',c_in_openai,openai_api_key,azure_openai_api_version,azure_openai_api_key,
375
+ # azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
376
 
377
 
378
 
379
+ # if os.getenv('AZURE_API_KEY') is None:
380
+ # st.write("---")
381
+ # st.subheader("OpenAI - Azure")
382
+ # st.markdown("This version OpenAI relies on Azure servers directly as is intended for private enterprise instances of OpenAI's services, such as [UM-GPT](https://its.umich.edu/computing/ai). Administrators will provide you with the following information.")
383
+ # azure_openai_api_version = st.text_input("azure_openai_api_version", os.environ.get('AZURE_API_VERSION', ''),
384
+ # help='API Version e.g. "2023-05-15"',
385
+ # placeholder = 'e.g. 2023-05-15',
386
+ # type='password')
387
+ # azure_openai_api_key = st.text_input("azure_openai_api_key", os.environ.get('AZURE_API_KEY', ''),
388
+ # help='The actual API key. Likely to be a 32-character string',
389
+ # placeholder = 'e.g. 12333333333333333333333333333332',
390
+ # type='password')
391
+ # azure_openai_api_base = st.text_input("azure_openai_api_base", os.environ.get('AZURE_API_BASE', ''),
392
+ # help='The base url for the API e.g. "https://api.umgpt.umich.edu/azure-openai-api"',
393
+ # placeholder = 'e.g. https://api.umgpt.umich.edu/azure-openai-api',
394
+ # type='password')
395
+ # azure_openai_organization = st.text_input("azure_openai_organization", os.environ.get('AZURE_ORGANIZATION', ''),
396
+ # help='Your organization code. Likely a short string',
397
+ # placeholder = 'e.g. 123456',
398
+ # type='password')
399
+ # azure_openai_api_type = st.text_input("azure_openai_api_type", os.environ.get('AZURE_API_TYPE', ''),
400
+ # help='The API type. Typically "azure"',
401
+ # placeholder = 'e.g. azure',
402
+ # type='password')
403
+ # with st.container():
404
+ # c_in_azure, c_button_azure = st.columns([10,2])
405
+ # with c_button_azure:
406
+ # st.empty()
407
+ # with st.container():
408
+ # with c_button_azure:
409
+ # st.write("##")
410
+ # st.button("Test Azure OpenAI", on_click=test_API, args=['azure_openai',c_in_azure,openai_api_key,azure_openai_api_version,azure_openai_api_key,
411
+ # azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
412
 
413
 
414
 
415
+ # if os.getenv('PALM_API_KEY') is None:
416
+ # st.write("---")
417
+ # st.subheader("Google PaLM 2")
418
+ # st.markdown('Follow these [instructions](https://developers.generativeai.google/tutorials/setup) to generate an API key for PaLM 2. You may need to also activate an account with [MakerSuite](https://makersuite.google.com/app/apikey) and enable "early access."')
419
+ # with st.container():
420
+ # c_in_palm, c_button_palm = st.columns([10,2])
421
+ # with c_in_palm:
422
+ # google_palm = st.text_input("Google PaLM 2 API Key", os.environ.get('PALM_API_KEY', ''),
423
+ # help='The MakerSuite API key e.g. a 32-character string',
424
+ # placeholder='e.g. SATgthsykuE64FgrrrrEervr3S4455t_geyDeGq',
425
+ # type='password')
426
+ # with st.container():
427
+ # with c_button_palm:
428
+ # st.write("##")
429
+ # st.button("Test PaLM 2", on_click=test_API, args=['palm',c_in_palm,openai_api_key,azure_openai_api_version,azure_openai_api_key,
430
+ # azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
431
+
432
+ # st.button("Set API Keys",type='primary', on_click=set_API_keys, args=[openai_api_key,azure_openai_api_version,azure_openai_api_key,
433
+ # azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm])
434
+
435
+ # # # UI form for entering environment variables if not all are set
436
+ # # with st.form("env_variables"):
437
+ # # for var, value in env_variables.items():
438
+ # # env_variables[var] = st.text_input(f"Enter {var}", value or "")
439
+ # # submitted = st.form_submit_button("Submit")
440
+ # # if submitted:
441
+ # # # Assuming the environment variables should be set for the session
442
+ # # for var, value in env_variables.items():
443
+ # # os.environ[var] = value
444
+ # # st.success("Environment variables updated. Please restart your app.")
445
+ # if st.button('Proceed to VoucherVision'):
446
+ # st.session_state.proceed_to_private = False
447
+ # st.session_state.proceed_to_main = True
448
+
449
+ # def set_API_keys(openai_api_key, azure_openai_api_version, azure_openai_api_key, azure_openai_api_base, azure_openai_organization, azure_openai_api_type, google_vision, google_palm):
450
+ # # Set the environment variable if the key is not None or an empty string
451
+ # if openai_api_key:
452
+ # os.environ['OPENAI_API_KEY'] = openai_api_key
453
+ # if azure_openai_api_version:
454
+ # os.environ['AZURE_API_VERSION'] = azure_openai_api_version
455
+ # if azure_openai_api_key:
456
+ # os.environ['AZURE_API_KEY'] = azure_openai_api_key
457
+ # if azure_openai_api_base:
458
+ # os.environ['AZURE_API_BASE'] = azure_openai_api_base
459
+ # if azure_openai_organization:
460
+ # os.environ['AZURE_ORGANIZATION'] = azure_openai_organization
461
+ # if azure_openai_api_type:
462
+ # os.environ['AZURE_API_TYPE'] = azure_openai_api_type
463
+ # if google_vision:
464
+ # os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = google_vision
465
+ # if google_palm:
466
+ # os.environ['GOOGLE_PALM_API'] = google_palm
467
+
468
+ # st.success("API keys set successfully!")
469
 
470
 
471
+ # def test_API(api, message_loc,openai_api_key,azure_openai_api_version,azure_openai_api_key, azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm):
472
+ # # Save the API keys
473
+ # # save_changes_to_API_keys(openai_api_key,azure_openai_api_version,azure_openai_api_key,azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm)
474
+ # set_API_keys(openai_api_key, azure_openai_api_version, azure_openai_api_key,
475
+ # azure_openai_api_base, azure_openai_organization, azure_openai_api_type,
476
+ # google_vision, google_palm)
477
 
478
+ # with st.spinner('Performing validation checks...'):
479
+ # if api == 'google_vision':
480
+ # print("*** Google Vision OCR API Key ***")
481
+ # try:
482
+ # demo_config_path = os.path.join(st.session_state.dir_home,'demo','validation_configs','google_vision_ocr_test.yaml')
483
+ # demo_images_path = os.path.join(st.session_state.dir_home, 'demo', 'demo_images')
484
+ # demo_out_path = os.path.join(st.session_state.dir_home, 'demo', 'demo_output','run_name')
485
+ # create_google_ocr_yaml_config(demo_config_path, demo_images_path, demo_out_path)
486
+ # voucher_vision_OCR_test(demo_config_path, st.session_state.dir_home, None, demo_images_path)
487
+ # with message_loc:
488
+ # st.success("Google Vision OCR API Key Valid :white_check_mark:")
489
+ # return True
490
+ # except Exception as e:
491
+ # with message_loc:
492
+ # st.error(f"Google Vision OCR API Key Failed! {e}")
493
+ # return False
494
 
495
+ # elif api == 'openai':
496
+ # print("*** OpenAI API Key ***")
497
+ # try:
498
+ # if run_api_tests('openai'):
499
+ # with message_loc:
500
+ # st.success("OpenAI API Key Valid :white_check_mark:")
501
+ # else:
502
+ # with message_loc:
503
+ # st.error("OpenAI API Key Failed:exclamation:")
504
+ # return False
505
+ # except Exception as e:
506
+ # with message_loc:
507
+ # st.error(f"OpenAI API Key Failed:exclamation: {e}")
508
+
509
+ # elif api == 'azure_openai':
510
+ # print("*** Azure OpenAI API Key ***")
511
+ # try:
512
+ # if run_api_tests('azure_openai'):
513
+ # with message_loc:
514
+ # st.success("Azure OpenAI API Key Valid :white_check_mark:")
515
+ # else:
516
+ # with message_loc:
517
+ # st.error(f"Azure OpenAI API Key Failed:exclamation:")
518
+ # return False
519
+ # except Exception as e:
520
+ # with message_loc:
521
+ # st.error(f"Azure OpenAI API Key Failed:exclamation: {e}")
522
+ # elif api == 'palm':
523
+ # print("*** Google PaLM 2 API Key ***")
524
+ # try:
525
+ # if run_api_tests('palm'):
526
+ # with message_loc:
527
+ # st.success("Google PaLM 2 API Key Valid :white_check_mark:")
528
+ # else:
529
+ # with message_loc:
530
+ # st.error("Google PaLM 2 API Key Failed:exclamation:")
531
+ # return False
532
+ # except Exception as e:
533
+ # with message_loc:
534
+ # st.error(f"Google PaLM 2 API Key Failed:exclamation: {e}")
535
 
536
 
537
  def save_changes_to_API_keys(cfg_private,openai_api_key,azure_openai_api_version,azure_openai_api_key,
 
1371
  if st.session_state.proceed_to_build_llm_prompt:
1372
  build_LLM_prompt_config()
1373
  elif st.session_state.proceed_to_private:
1374
+ # create_private_file()
1375
+ pass
1376
  elif st.session_state.proceed_to_main:
1377
  main()