Seymour-Visions commited on
Commit
aabd623
·
verified ·
1 Parent(s): 092f5a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -2,16 +2,31 @@ import gradio as gr
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
  import logging
 
 
5
 
6
  logging.basicConfig(level=logging.DEBUG)
7
  logger = logging.getLogger(__name__)
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
10
  tokenizer = AutoTokenizer.from_pretrained(model_id)
11
  model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.float16)
12
 
13
  def respond(message, history):
14
- messages = []
15
  for human, assistant in history:
16
  messages.append({"role": "user", "content": human})
17
  messages.append({"role": "assistant", "content": assistant})
 
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
  import logging
5
+ from huggingface_hub import login
6
+ import os
7
 
8
  logging.basicConfig(level=logging.DEBUG)
9
  logger = logging.getLogger(__name__)
10
 
11
+ # Read the system message from the file
12
+ with open("system_message.txt", "r") as file:
13
+ system_message = file.read().strip()
14
+
15
+ # Get the Hugging Face token from environment variables
16
+ hf_token = os.getenv('HF_TOKEN')
17
+ if hf_token is None:
18
+ logger.error("HF_TOKEN environment variable is not set")
19
+ raise ValueError("HF_TOKEN environment variable is not set")
20
+
21
+ # Authenticate with Hugging Face
22
+ login(token=testkey)
23
+
24
  model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
25
  tokenizer = AutoTokenizer.from_pretrained(model_id)
26
  model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.float16)
27
 
28
  def respond(message, history):
29
+ messages = [{"role": "system", "content": system_message}]
30
  for human, assistant in history:
31
  messages.append({"role": "user", "content": human})
32
  messages.append({"role": "assistant", "content": assistant})