matdmiller commited on
Commit
dc3a0c9
·
1 Parent(s): 0edab04

api key import fix

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.ipynb +18 -3
  3. app.py +9 -2
.gitignore CHANGED
@@ -1,4 +1,5 @@
1
  tts_openai_secrets.py
 
2
 
3
  # Byte-compiled / optimized / DLL files
4
  __pycache__/
 
1
  tts_openai_secrets.py
2
+ tts_openai_secrets*
3
 
4
  # Byte-compiled / optimized / DLL files
5
  __pycache__/
app.ipynb CHANGED
@@ -15,16 +15,31 @@
15
  "execution_count": null,
16
  "id": "667802a7-0f36-4136-a381-e66210b20462",
17
  "metadata": {},
18
- "outputs": [],
 
 
 
 
 
 
 
 
19
  "source": [
20
  "#| export\n",
21
  "#tts_openai_secrets.py content:\n",
22
  "#import os\n",
23
  "#os.environ['OPENAI_API_KEY'] = 'sk-XXXXXXXXXXXXXXXXXXXXXX'\n",
24
  "try:\n",
25
- " import tts_openai_secrets\n",
 
 
26
  "except:\n",
27
- " print('secret import from tts_openai_secrets.py failed - env var must be previously set')"
 
 
 
 
 
28
  ]
29
  },
30
  {
 
15
  "execution_count": null,
16
  "id": "667802a7-0f36-4136-a381-e66210b20462",
17
  "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "name": "stdout",
21
+ "output_type": "stream",
22
+ "text": [
23
+ "OPENAI_API_KEY var not found. Trying import tts_openai_secrets\n"
24
+ ]
25
+ }
26
+ ],
27
  "source": [
28
  "#| export\n",
29
  "#tts_openai_secrets.py content:\n",
30
  "#import os\n",
31
  "#os.environ['OPENAI_API_KEY'] = 'sk-XXXXXXXXXXXXXXXXXXXXXX'\n",
32
  "try:\n",
33
+ " import os\n",
34
+ " _ = os.environ['OPENAI_API_KEY']\n",
35
+ " print('OPENAI_API_KEY var was found.')\n",
36
  "except:\n",
37
+ " print('OPENAI_API_KEY var not found. Trying import tts_openai_secrets')\n",
38
+ " try:\n",
39
+ " import tts_openai_secrets\n",
40
+ " print('import tts_openai_secrets succeeded')\n",
41
+ " except:\n",
42
+ " print('secret import from tts_openai_secrets.py failed - env var must be previously set')"
43
  ]
44
  },
45
  {
app.py CHANGED
@@ -8,9 +8,16 @@ __all__ = ['tts_models', 'tts_voices', 'client', 'create_speech', 'get_input_tex
8
  #import os
9
  #os.environ['OPENAI_API_KEY'] = 'sk-XXXXXXXXXXXXXXXXXXXXXX'
10
  try:
11
- import tts_openai_secrets
 
 
12
  except:
13
- print('secret import from tts_openai_secrets.py failed - env var must be previously set')
 
 
 
 
 
14
 
15
  # %% app.ipynb 3
16
  import gradio as gr
 
8
  #import os
9
  #os.environ['OPENAI_API_KEY'] = 'sk-XXXXXXXXXXXXXXXXXXXXXX'
10
  try:
11
+ import os
12
+ _ = os.environ['OPENAI_API_KEY']
13
+ print('OPENAI_API_KEY var was found.')
14
  except:
15
+ print('OPENAI_API_KEY var not found. Trying import tts_openai_secrets')
16
+ try:
17
+ import tts_openai_secrets
18
+ print('import tts_openai_secrets succeeded')
19
+ except:
20
+ print('secret import from tts_openai_secrets.py failed - env var must be previously set')
21
 
22
  # %% app.ipynb 3
23
  import gradio as gr