Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,43 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
st.title("LLaMA Chatbot")
|
8 |
-
st.write("Status: Basic app structure loaded")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
6 |
|
7 |
+
# Set your HuggingFace token
|
8 |
+
hf_token = st.secrets["HF_TOKEN25"] # Using Streamlit secrets
|
9 |
+
try:
|
10 |
+
login(token=hf_token)
|
11 |
+
st.success("Successfully logged in to Hugging Face!")
|
12 |
+
except Exception as e:
|
13 |
+
st.error(f"Error logging in to Hugging Face: {str(e)}")
|
14 |
|
15 |
st.title("LLaMA Chatbot")
|
|
|
16 |
|
17 |
+
@st.cache_resource
|
18 |
+
def load_model():
|
19 |
+
try:
|
20 |
+
model_path = "Alaaeldin/llama2-app"
|
21 |
+
st.info("Loading model... This might take a minute.")
|
22 |
+
|
23 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, token=hf_token)
|
24 |
+
model = AutoModelForCausalLM.from_pretrained(
|
25 |
+
model_path,
|
26 |
+
torch_dtype=torch.float16,
|
27 |
+
device_map="auto",
|
28 |
+
load_in_8bit=True,
|
29 |
+
token=hf_token
|
30 |
+
)
|
31 |
+
st.success("✅ Model loaded successfully!")
|
32 |
+
return model, tokenizer
|
33 |
+
except Exception as e:
|
34 |
+
st.error(f"❌ Error loading model: {str(e)}")
|
35 |
+
return None, None
|
36 |
+
|
37 |
+
model, tokenizer = load_model()
|
38 |
+
|
39 |
+
# Add a text input
|
40 |
+
if model and tokenizer:
|
41 |
+
user_input = st.text_input("Your message:", "")
|
42 |
+
if st.button("Send"):
|
43 |
+
st.write("User:", user_input)
|