Tonic commited on
Commit
af4feb8
1 Parent(s): 53e6055

add environement variables

Browse files
Files changed (2) hide show
  1. app.py +16 -3
  2. requirements.txt +2 -1
app.py CHANGED
@@ -15,25 +15,38 @@ from huggingface_hub import InferenceClient
15
  import openai
16
  from openai import OpenAI
17
  from globalvars import API_BASE, API_KEY, intention_prompt
 
18
 
19
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:30'
20
  os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
21
  os.environ['CUDA_CACHE_DISABLE'] = '1'
22
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
23
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ## add chroma vector store
25
 
26
 
27
  ## use instruct embeddings
28
  # Load the tokenizer and model
29
- tokenizer = AutoTokenizer.from_pretrained('nvidia/NV-Embed-v1', trust_remote_code=True)
30
- model = AutoModel.from_pretrained('nvidia/NV-Embed-v1', trust_remote_code=True).to(device)
31
 
32
 
33
  ## Make intention Mapper
34
 
35
  intention_client = OpenAI(
36
- api_key=API_KEY,
37
  base_url=API_BASE
38
  )
39
  intention_completion = intention_client.chat.completions.create(
 
15
  import openai
16
  from openai import OpenAI
17
  from globalvars import API_BASE, API_KEY, intention_prompt
18
+ from dotenv import load_dotenv
19
 
20
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:30'
21
  os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
22
  os.environ['CUDA_CACHE_DISABLE'] = '1'
23
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
24
 
25
+ def load_env_variables():
26
+ # Load the .env file
27
+ load_dotenv()
28
+
29
+ # Retrieve the environment variables
30
+ hf_token = os.getenv('HF_TOKEN')
31
+ yi_token = os.getenv('YI_TOKEN')
32
+
33
+ return hf_token, yi_token
34
+
35
+ # Example usage
36
+ hf_token, yi_token = load_env_variables()
37
  ## add chroma vector store
38
 
39
 
40
  ## use instruct embeddings
41
  # Load the tokenizer and model
42
+ tokenizer = AutoTokenizer.from_pretrained('nvidia/NV-Embed-v1', token = hf_token , trust_remote_code=True)
43
+ model = AutoModel.from_pretrained('nvidia/NV-Embed-v1' , token = hf_token , trust_remote_code=True).to(device)
44
 
45
 
46
  ## Make intention Mapper
47
 
48
  intention_client = OpenAI(
49
+ api_key=yi_token,
50
  base_url=API_BASE
51
  )
52
  intention_completion = intention_client.chat.completions.create(
requirements.txt CHANGED
@@ -3,4 +3,5 @@ einops
3
  sentence-transformers
4
  torch==2.2.0
5
  transformers
6
- openai
 
 
3
  sentence-transformers
4
  torch==2.2.0
5
  transformers
6
+ openai
7
+ python-dotenv