Alaaeldin commited on
Commit
9a2f868
Β·
verified Β·
1 Parent(s): 6bb7d92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -39
app.py CHANGED
@@ -6,52 +6,18 @@ from huggingface_hub import login
6
 
7
  # Set page config for better display
8
  st.set_page_config(page_title="LLaMA Chatbot", page_icon="πŸ¦™")
9
-
10
- # Create a status placeholder
11
  status_placeholder = st.empty()
12
 
13
  # Set your HuggingFace token
14
- hf_token = st.secrets["HF_TOKEN25"]
15
  try:
 
 
16
  login(token=hf_token)
17
  status_placeholder.success("πŸ”‘ Successfully logged in to Hugging Face!")
18
  except Exception as e:
19
- status_placeholder.error(f"🚫 Error logging in to Hugging Face: {str(e)}")
 
20
 
21
  st.title("πŸ¦™ LLaMA Chatbot")
22
 
23
- @st.cache_resource
24
- def load_model():
25
- try:
26
- model_path = "Alaaeldin/llama2-app"
27
-
28
- # Update status for tokenizer loading
29
- status_placeholder.info("πŸ”„ Loading tokenizer...")
30
- tokenizer = AutoTokenizer.from_pretrained(model_path, token=hf_token)
31
- status_placeholder.success("βœ… Tokenizer loaded successfully!")
32
-
33
- # Update status for model loading
34
- status_placeholder.info("πŸ”„ Loading model... This might take a minute.")
35
- model = AutoModelForCausalLM.from_pretrained(
36
- model_path,
37
- torch_dtype=torch.float16,
38
- device_map="auto",
39
- load_in_8bit=True,
40
- token=hf_token
41
- )
42
- status_placeholder.success("βœ… Model loaded successfully!")
43
-
44
- # Final success message
45
- st.success("✨ System is ready! You can now start chatting with the model.")
46
- return model, tokenizer
47
- except Exception as e:
48
- status_placeholder.error(f"❌ Error loading model: {str(e)}")
49
- return None, None
50
-
51
- model, tokenizer = load_model()
52
-
53
- # Add a text input
54
- if model and tokenizer:
55
- user_input = st.text_input("Your message:", "")
56
- if st.button("Send"):
57
- st.write("User:", user_input)
 
6
 
7
  # Set page config for better display
8
  st.set_page_config(page_title="LLaMA Chatbot", page_icon="πŸ¦™")
 
 
9
  status_placeholder = st.empty()
10
 
11
  # Set your HuggingFace token
 
12
  try:
13
+ hf_token = st.secrets["HF_TOKEN25"]
14
+ status_placeholder.success("πŸ”‘ Successfully found HF token in secrets!")
15
  login(token=hf_token)
16
  status_placeholder.success("πŸ”‘ Successfully logged in to Hugging Face!")
17
  except Exception as e:
18
+ status_placeholder.error(f"🚫 Error with HF token: {str(e)}")
19
+ st.stop()
20
 
21
  st.title("πŸ¦™ LLaMA Chatbot")
22
 
23
+ # Rest of the code...