pradeepsengarr commited on
Commit
fc92fad
·
verified ·
1 Parent(s): bde561e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -3,18 +3,19 @@ import torch
3
  from transformers import AutoTokenizer, AutoModelForCausalLM
4
  import os
5
 
6
- # Load Hugging Face token from environment variable (Set this in Hugging Face Secrets)
7
  hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
8
- if not hf_token:
9
- st.error("Hugging Face token not found! Please add it to Secrets in Hugging Face Spaces.")
 
10
  st.stop()
11
 
12
- # Load the model and tokenizer
13
  MODEL_NAME = "google/gemma-2b-it"
 
 
14
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_auth_token=hf_token)
15
- model = AutoModelForCausalLM.from_pretrained(
16
- MODEL_NAME, torch_dtype=torch.float16, device_map="auto", use_auth_token=hf_token
17
- )
18
 
19
  # Streamlit UI
20
  st.title("Gemma-2B Code Assistant")
 
3
  from transformers import AutoTokenizer, AutoModelForCausalLM
4
  import os
5
 
6
+ # Load Hugging Face Token from environment variable
7
  hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
8
+
9
+ if hf_token is None:
10
+ st.error("❌ Hugging Face API Token is missing! Add it in Settings → Secrets.")
11
  st.stop()
12
 
13
+ # Model name
14
  MODEL_NAME = "google/gemma-2b-it"
15
+
16
+ # Load tokenizer and model with authentication
17
  tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_auth_token=hf_token)
18
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto", use_auth_token=hf_token)
 
 
19
 
20
  # Streamlit UI
21
  st.title("Gemma-2B Code Assistant")