Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,30 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
# st.warning("Large Language Models (LLMs) like Llama 2-70b can be resource-intensive. This is a simplified demo. Loading the full model might exceed memory limits on standard machines.")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
def load_demo_model():
|
| 13 |
-
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-13b-hf")
|
| 14 |
-
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-13b-hf")
|
| 15 |
-
# ... Add logic to load a tiny slice of the model ...
|
| 16 |
-
return tokenizer, model
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
# with st.spinner("Loading model (this might still take some time)..."):
|
| 21 |
-
#
|
| 22 |
-
# st.success("Demo model loaded!")
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
generated_text =
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
+
# Your model and tokenizer definitions remain the same
|
| 5 |
+
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
| 8 |
|
| 9 |
+
st.title("Chat with the Language Model")
|
|
|
|
| 10 |
|
| 11 |
+
# Area to display chat history
|
| 12 |
+
chat_history = st.empty()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# User input box
|
| 15 |
+
user_input = st.text_input("Your message:", key="input")
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Submit button
|
| 18 |
+
if st.button('Send'):
|
| 19 |
+
# Add user message to chat history
|
| 20 |
+
messages.append({"role": "user", "content": user_input})
|
| 21 |
+
chat_history.text("\n".join([f"**{msg['role']}**: {msg['content']}" for msg in messages]))
|
| 22 |
|
| 23 |
+
# Process the input with the model
|
| 24 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
| 25 |
+
outputs = model.generate(inputs, max_new_tokens=20)
|
| 26 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
+
|
| 28 |
+
# Add model response to chat history
|
| 29 |
+
messages.append({"role": "assistant", "content": generated_text})
|
| 30 |
+
chat_history.text("\n".join([f"**{msg['role']}**: {msg['content']}" for msg in messages]))
|