addcorpbc commited on
Commit ·
e94a060
1
Parent(s): ae4399d
Update app.py to include Hugging Face token handling
Browse files2 unmodified lines34566788910111213141516171518192021222023242526272 unmodified linesimport os
# Authenticate using a token from environment variableshf_token = os.getenv("HF_TOKEN")hf_token = os.getenv("HFTOKEN") # Updated to match your environment variable nameif not hf_token: raise ValueError("Hugging Face token is missing. Please add it as an environment variable.") raise ValueError("Hugging Face token is missing. Please add it as an environment variable named 'HFTOKEN'.") # Print the token for debuggingprint("Hugging Face Token:", hf_token)
# Set up caching directorycache_dir = "./model_cache"os.makedirs(cache_dir, exist_ok=True)
# Load LLaMA model and tokenizertokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf", cache_dir=cache_dir)tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf", cache_dir=cache_dir, use_auth_token=hf_token)model = AutoModelForCausalLM.from_pretrained( "meta-llama/Llama-2-7b-hf", load_in_8bit=True, # Enable quantization for better performance device_map="auto", # Automatically map layers to available hardware cache_dir=cache_dir cache_dir=cache_dir, use_auth_token=hf_token # Pass the token for authenticated model loading)
def recommend(user_input):app.py+8-4