Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,7 @@ def load_model():
|
|
| 24 |
return tokenizer, model
|
| 25 |
|
| 26 |
tokenizer, model = load_model()
|
|
|
|
| 27 |
# Function to generate chatbot response using the provided template
|
| 28 |
def get_completion(query: str, model, tokenizer) -> str:
|
| 29 |
device = "cuda:0" if torch.cuda.is_available() else "cpu" #Use cuda if available.
|
|
@@ -52,13 +53,11 @@ def get_completion(query: str, model, tokenizer) -> str:
|
|
| 52 |
return model_response
|
| 53 |
|
| 54 |
# Streamlit app
|
| 55 |
-
st.title("
|
| 56 |
|
| 57 |
# Initialize chat history
|
| 58 |
if "messages" not in st.session_state:
|
| 59 |
st.session_state.messages = []
|
| 60 |
-
if "chat_history" not in st.session_state:
|
| 61 |
-
st.session_state.chat_history = ""
|
| 62 |
|
| 63 |
# Display chat messages from history on app rerun
|
| 64 |
for message in st.session_state.messages:
|
|
@@ -66,7 +65,7 @@ for message in st.session_state.messages:
|
|
| 66 |
st.markdown(message["content"])
|
| 67 |
|
| 68 |
# Accept user input
|
| 69 |
-
if prompt := st.chat_input("
|
| 70 |
# Add user message to chat history
|
| 71 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 72 |
# Display user message in chat message container
|
|
@@ -77,7 +76,7 @@ if prompt := st.chat_input("What is up?"):
|
|
| 77 |
with st.chat_message("assistant"):
|
| 78 |
message_placeholder = st.empty()
|
| 79 |
full_response = ""
|
| 80 |
-
response =
|
| 81 |
|
| 82 |
# Simulate stream of responses with milliseconds delay
|
| 83 |
import time
|
|
@@ -89,6 +88,4 @@ if prompt := st.chat_input("What is up?"):
|
|
| 89 |
message_placeholder.markdown(full_response)
|
| 90 |
|
| 91 |
# Add assistant response to chat history
|
| 92 |
-
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
| 93 |
-
#update the chat history.
|
| 94 |
-
st.session_state.chat_history += prompt + response
|
|
|
|
| 24 |
return tokenizer, model
|
| 25 |
|
| 26 |
tokenizer, model = load_model()
|
| 27 |
+
|
| 28 |
# Function to generate chatbot response using the provided template
|
| 29 |
def get_completion(query: str, model, tokenizer) -> str:
|
| 30 |
device = "cuda:0" if torch.cuda.is_available() else "cpu" #Use cuda if available.
|
|
|
|
| 53 |
return model_response
|
| 54 |
|
| 55 |
# Streamlit app
|
| 56 |
+
st.title("Gemma-2b-it Support Chatbot")
|
| 57 |
|
| 58 |
# Initialize chat history
|
| 59 |
if "messages" not in st.session_state:
|
| 60 |
st.session_state.messages = []
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# Display chat messages from history on app rerun
|
| 63 |
for message in st.session_state.messages:
|
|
|
|
| 65 |
st.markdown(message["content"])
|
| 66 |
|
| 67 |
# Accept user input
|
| 68 |
+
if prompt := st.chat_input("How can I help you?"):
|
| 69 |
# Add user message to chat history
|
| 70 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 71 |
# Display user message in chat message container
|
|
|
|
| 76 |
with st.chat_message("assistant"):
|
| 77 |
message_placeholder = st.empty()
|
| 78 |
full_response = ""
|
| 79 |
+
response = get_completion(prompt, model, tokenizer)
|
| 80 |
|
| 81 |
# Simulate stream of responses with milliseconds delay
|
| 82 |
import time
|
|
|
|
| 88 |
message_placeholder.markdown(full_response)
|
| 89 |
|
| 90 |
# Add assistant response to chat history
|
| 91 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
|
|
|
|
|