Update app.py
Browse files
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
|
|
|
20 |
|
21 |
st.title("π¦ LLaMA Chatbot")
|
22 |
|
23 |
-
|
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...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|