GeorgiosIoannouCoder commited on
Commit
740868b
1 Parent(s): e62ab21

Update tokens.md

Browse files
Files changed (1) hide show
  1. tokens.md +13 -3
tokens.md CHANGED
@@ -18,24 +18,33 @@
18
  - Create new API key
19
  - Copy the key
20
 
21
- ## 2. Add Tokens to Space Settings
 
 
 
22
  1. Go INTO your Hugging Face Space settings (⚙️ icon)
23
  2. Find "Variables and secrets" section
24
  3. Add tokens as "New secret" one by one:
25
  ```toml
26
- MONGO_URI = "your_mongo_uri"
27
  HUGGINGFACEHUB_API_TOKEN = "your_huggingface_token_here"
28
  OPENAI_API_KEY = "your_openai_key_here"
 
29
  ```
30
 
31
- ## 3. Access Tokens in app.py
 
 
32
 
 
33
  ```python
34
  import os
 
35
 
36
  # Load environment variable(s)
 
37
  HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
38
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
 
39
  ```
40
 
41
  ## Alternative Methods
@@ -44,6 +53,7 @@ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
44
  # .streamlit/secrets.toml
45
  HUGGINGFACEHUB_API_TOKEN = "your_token_here"
46
  OPENAI_API_KEY = "your_key_here"
 
47
  ```
48
 
49
  ## Security Best Practices
 
18
  - Create new API key
19
  - Copy the key
20
 
21
+ 3. **MongoDB URI**:
22
+ - Follow [here](https://huggingface.co/spaces/GeorgiosIoannouCoder/cuny-tech-prep-tutorial-5/blob/main/mongodb_atlas_vector_search_setup.md#connection-string)
23
+
24
+ ## 2. Add Tokens to Hugging Face Space Settings
25
  1. Go INTO your Hugging Face Space settings (⚙️ icon)
26
  2. Find "Variables and secrets" section
27
  3. Add tokens as "New secret" one by one:
28
  ```toml
 
29
  HUGGINGFACEHUB_API_TOKEN = "your_huggingface_token_here"
30
  OPENAI_API_KEY = "your_openai_key_here"
31
+ MONGO_URI = "your_mongo_uri"
32
  ```
33
 
34
+ ## 3. Add Access Tokens in app.py
35
+
36
+ ### NOTE: pip install python-dotenv
37
 
38
+ #### [python-dotenv](https://pypi.org/project/python-dotenv/) gives access to load_dotenv, find_dotenv
39
  ```python
40
  import os
41
+ from dotenv import load_dotenv, find_dotenv
42
 
43
  # Load environment variable(s)
44
+ load_dotenv(find_dotenv())
45
  HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
46
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
47
+ MONGO_URI = os.getenv("MONGO_URI")
48
  ```
49
 
50
  ## Alternative Methods
 
53
  # .streamlit/secrets.toml
54
  HUGGINGFACEHUB_API_TOKEN = "your_token_here"
55
  OPENAI_API_KEY = "your_key_here"
56
+ MONGO_URI = "your_mongodb_uri_here"
57
  ```
58
 
59
  ## Security Best Practices