Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,8 @@ model.to(device)
|
|
14 |
# Initialize chat history
|
15 |
if 'history' not in st.session_state:
|
16 |
st.session_state['history'] = []
|
|
|
|
|
17 |
|
18 |
def generate_response(input_text):
|
19 |
# Encode the new user input, add end of string token
|
@@ -39,11 +41,20 @@ def generate_response(input_text):
|
|
39 |
# Update session state history with the new tokens (flattened)
|
40 |
st.session_state['history'] = chat_history_ids[0].tolist()
|
41 |
|
|
|
|
|
|
|
|
|
42 |
return bot_output
|
43 |
|
44 |
# Streamlit Interface
|
45 |
st.title("Chat with DialoGPT")
|
46 |
|
|
|
|
|
|
|
|
|
|
|
47 |
# Create input box for user
|
48 |
user_input = st.text_input("You: ", "")
|
49 |
|
|
|
14 |
# Initialize chat history
|
15 |
if 'history' not in st.session_state:
|
16 |
st.session_state['history'] = []
|
17 |
+
if 'conversation' not in st.session_state:
|
18 |
+
st.session_state['conversation'] = []
|
19 |
|
20 |
def generate_response(input_text):
|
21 |
# Encode the new user input, add end of string token
|
|
|
41 |
# Update session state history with the new tokens (flattened)
|
42 |
st.session_state['history'] = chat_history_ids[0].tolist()
|
43 |
|
44 |
+
# Add both user input and bot response to the conversation history for display
|
45 |
+
st.session_state['conversation'].append(f"You: {input_text}")
|
46 |
+
st.session_state['conversation'].append(f"Bot: {bot_output}")
|
47 |
+
|
48 |
return bot_output
|
49 |
|
50 |
# Streamlit Interface
|
51 |
st.title("Chat with DialoGPT")
|
52 |
|
53 |
+
# Display the conversation history
|
54 |
+
if st.session_state['conversation']:
|
55 |
+
for message in st.session_state['conversation']:
|
56 |
+
st.markdown(f"<p style='color:gray; padding:5px;'>{message}</p>", unsafe_allow_html=True)
|
57 |
+
|
58 |
# Create input box for user
|
59 |
user_input = st.text_input("You: ", "")
|
60 |
|