AlexanderKazakov commited on
Commit
1f71841
1 Parent(s): f554908

keys as env variables

Browse files
gradio_app/backend/ChatGptInteractor.py CHANGED
@@ -1,12 +1,20 @@
1
  import logging
 
2
  import time
3
 
4
  import tiktoken
5
  import openai
6
 
7
 
8
- with open('data/openaikey.txt') as f:
9
- OPENAI_KEY = f.read().strip()
 
 
 
 
 
 
 
10
  openai.api_key = OPENAI_KEY
11
 
12
 
 
1
  import logging
2
+ import os
3
  import time
4
 
5
  import tiktoken
6
  import openai
7
 
8
 
9
+ OPENAI_KEY = None
10
+ key_file = 'data/openaikey.txt'
11
+ if os.path.exists(key_file):
12
+ with open(key_file) as f:
13
+ OPENAI_KEY = f.read().strip()
14
+
15
+ if OPENAI_KEY is None:
16
+ OPENAI_KEY = os.getenv('OPENAI_KEY')
17
+
18
  openai.api_key = OPENAI_KEY
19
 
20
 
gradio_app/backend/HuggingfaceGenerator.py CHANGED
@@ -1,10 +1,19 @@
1
  import logging
 
2
 
3
  from huggingface_hub import InferenceClient
4
  from transformers import AutoTokenizer
5
 
6
- with open('data/hftoken.txt') as f:
7
- HF_TOKEN = f.read().strip()
 
 
 
 
 
 
 
 
8
 
9
  logging.basicConfig(level=logging.INFO)
10
  logger = logging.getLogger(__name__)
 
1
  import logging
2
+ import os
3
 
4
  from huggingface_hub import InferenceClient
5
  from transformers import AutoTokenizer
6
 
7
+
8
+ HF_TOKEN = None
9
+ key_file = 'data/hftoken.txt'
10
+ if os.path.exists(key_file):
11
+ with open(key_file) as f:
12
+ HF_TOKEN = f.read().strip()
13
+
14
+ if HF_TOKEN is None:
15
+ HF_TOKEN = os.getenv('HF_TOKEN')
16
+
17
 
18
  logging.basicConfig(level=logging.INFO)
19
  logger = logging.getLogger(__name__)