addcorpbc commited on
Commit ·
e94a060
1
Parent(s): ae4399d
Update app.py to include Hugging Face token handling
Browse files2 unmodified lines345678910111213141516171819202122232 unmodified linesimport os# Authenticate using a token from environment variableshf_token = os.getenv("HF_TOKEN")if not hf_token:raise ValueError("Hugging Face token is missing. Please add it as an environment variable.")# 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)model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf",load_in_8bit=True, # Enable quantization for better performancedevice_map="auto", # Automatically map layers to available hardwarecache_dir=cache_dir)def recommend(user_input):2 unmodified lines34567891011121314151617181920212223242526272 unmodified linesimport os# Authenticate using a token from environment variableshf_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 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, use_auth_token=hf_token)model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf",load_in_8bit=True, # Enable quantization for better performancedevice_map="auto", # Automatically map layers to available hardwarecache_dir=cache_dir,use_auth_token=hf_token # Pass the token for authenticated model loading)def recommend(user_input):
app.py+8-4