Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import gradio as gr
|
|
4 |
import torch
|
5 |
import logging
|
6 |
import sys
|
|
|
7 |
from accelerate import infer_auto_device_map, init_empty_weights
|
8 |
|
9 |
# Configure logging
|
@@ -13,6 +14,12 @@ logging.basicConfig(
|
|
13 |
)
|
14 |
logger = logging.getLogger(__name__)
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Define the model name
|
17 |
model_name = "meta-llama/Llama-2-7b-hf"
|
18 |
|
@@ -33,7 +40,7 @@ try:
|
|
33 |
tokenizer = AutoTokenizer.from_pretrained(
|
34 |
model_name,
|
35 |
trust_remote_code=True,
|
36 |
-
token=
|
37 |
)
|
38 |
tokenizer.pad_token = tokenizer.eos_token
|
39 |
logger.info("Tokenizer loaded successfully")
|
@@ -44,7 +51,7 @@ try:
|
|
44 |
model_name,
|
45 |
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
46 |
trust_remote_code=True,
|
47 |
-
token=
|
48 |
device_map="auto",
|
49 |
load_in_8bit=True
|
50 |
)
|
|
|
4 |
import torch
|
5 |
import logging
|
6 |
import sys
|
7 |
+
import os
|
8 |
from accelerate import infer_auto_device_map, init_empty_weights
|
9 |
|
10 |
# Configure logging
|
|
|
14 |
)
|
15 |
logger = logging.getLogger(__name__)
|
16 |
|
17 |
+
# Get HuggingFace token from environment variable
|
18 |
+
hf_token = os.environ.get('HUGGINGFACE_TOKEN')
|
19 |
+
if not hf_token:
|
20 |
+
logger.error("HUGGINGFACE_TOKEN environment variable not set")
|
21 |
+
raise ValueError("Please set the HUGGINGFACE_TOKEN environment variable")
|
22 |
+
|
23 |
# Define the model name
|
24 |
model_name = "meta-llama/Llama-2-7b-hf"
|
25 |
|
|
|
40 |
tokenizer = AutoTokenizer.from_pretrained(
|
41 |
model_name,
|
42 |
trust_remote_code=True,
|
43 |
+
token=hf_token
|
44 |
)
|
45 |
tokenizer.pad_token = tokenizer.eos_token
|
46 |
logger.info("Tokenizer loaded successfully")
|
|
|
51 |
model_name,
|
52 |
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
53 |
trust_remote_code=True,
|
54 |
+
token=hf_token,
|
55 |
device_map="auto",
|
56 |
load_in_8bit=True
|
57 |
)
|