Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import torch
|
|
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
from peft import PeftModel, PeftConfig
|
5 |
from huggingface_hub import login
|
@@ -8,16 +9,30 @@ from huggingface_hub import login
|
|
8 |
st.set_page_config(page_title="LLaMA Chatbot", page_icon="π¦")
|
9 |
status_placeholder = st.empty()
|
10 |
|
11 |
-
#
|
12 |
try:
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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...
|
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
+
import os
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
from peft import PeftModel, PeftConfig
|
6 |
from huggingface_hub import login
|
|
|
9 |
st.set_page_config(page_title="LLaMA Chatbot", page_icon="π¦")
|
10 |
status_placeholder = st.empty()
|
11 |
|
12 |
+
# Try multiple ways to get the token
|
13 |
try:
|
14 |
+
# Try environment variable first
|
15 |
+
hf_token = os.environ.get("HF_TOKEN")
|
16 |
+
|
17 |
+
if not hf_token:
|
18 |
+
# Try Streamlit secrets
|
19 |
+
hf_token = st.secrets.get("HF_TOKEN")
|
20 |
+
|
21 |
+
if not hf_token:
|
22 |
+
raise ValueError("Token not found in any location")
|
23 |
+
|
24 |
+
status_placeholder.success("π Successfully found HF token!")
|
25 |
login(token=hf_token)
|
26 |
status_placeholder.success("π Successfully logged in to Hugging Face!")
|
27 |
+
|
28 |
except Exception as e:
|
29 |
status_placeholder.error(f"π« Error with HF token: {str(e)}")
|
30 |
+
st.error("Please ensure the token is properly set in the Space settings")
|
31 |
+
st.info("Current search paths for token:")
|
32 |
+
st.code("""
|
33 |
+
1. Environment variable: HF_TOKEN
|
34 |
+
2. Streamlit secrets: secrets.toml
|
35 |
+
""")
|
36 |
st.stop()
|
37 |
|
38 |
+
st.title("π¦ LLaMA Chatbot")
|
|
|
|