Spaces:
Runtime error
Runtime error
import streamlit as st | |
st.set_page_config(page_title="API_Keys", page_icon=":secret:") | |
st.markdown("# Manage your API keys") | |
st.markdown( | |
""" | |
Through out this term, you will use your API keys to access different servers such as Hugging Face and ChatGPT. | |
It is important to have a secured managment of your API keys on your computer. | |
**:red[REMEMBER:]** | |
Never display your keys in your code! | |
- To get your **:blue[OpenAI]** key, you can follow the link [here](https://elephas.app/blog/how-to-get-chatgpt-api-key-clh93ii2e1642073tpacu6w934j) | |
- To get your **:green[Hugging Face]** API key, you can follow the steps below: | |
1. Click on your profile image(of Hugging Face) and click your account name under "Profile"; | |
2. In the left bar of your profile, click on "Settings"; | |
3. In the left bar of the Settings page, click on "Access Tokens"; | |
4. Click on "Copy the token" button, just right to the button "Show" | |
5. Then you have copied your token in the clipboard, we can now moving on to store it locally. | |
""" | |
) | |
st.write("##") | |
st.markdown( | |
""" | |
#### Store API keys in the local environment | |
###### :blue[For MacOS/Linux:] | |
```bash | |
# 1. create .env file, for notebook, this can be done in your Jupyter notebook cell wiht "!" as prefix | |
touch .env | |
#2. hard code your key to .env | |
echo "HF_API_KEY=<Your Key here>" >> .env | |
``` | |
###### :blue[For windows] | |
- Using the option 2 from the [link](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety ) | |
###### :blue[REMEMBER]: | |
- Different API keys should have different names! For example: | |
- For OpenAI (ChatGPT), your name of key should be "OPENAI_API_KEY"; | |
- For Hugging Face, your name of key should be "HF_API_KEY" | |
""" | |
) | |
st.write("##") | |
st.markdown( | |
""" | |
#### Using your keys in notebook | |
Once we have done above successfully, we can call our API keys in Jupyter Notebook | |
1. Fistly, we install a convinient library | |
```cmd | |
!pip install python-dotenv | |
``` | |
remember: the prefix "!" is for Jupyter Notebook code cell only, if you are using command line directly, you don't need it. | |
2. using the code snippet below in jupyter notebook code cell. | |
```python | |
import os | |
from dotenv import load_dotenv | |
load_dotenv() | |
HF_API_KEY = os.getenv('HF_API_KEY') ## I use Hugging Face API key here as an example. | |
``` | |
- You can then execute the following code in notebook to check if it is succeed | |
```python | |
print(HF_API_KEY) | |
# Remember: this is only in your notebook cell, for your own check, do not submit this to our code space later on. | |
``` | |
""" | |
) |