Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -43,11 +43,7 @@ model_name = 'KhantKyaw/Chat_GPT-2'
|
|
43 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
44 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
st.title("Chat with GPT-2")
|
51 |
|
52 |
# Initialize chat history
|
53 |
if "messages" not in st.session_state:
|
@@ -55,21 +51,22 @@ if "messages" not in st.session_state:
|
|
55 |
|
56 |
# Display chat messages from history on app rerun
|
57 |
for message in st.session_state.messages:
|
58 |
-
with st.
|
59 |
-
st.markdown(
|
60 |
|
61 |
# React to user input
|
62 |
-
prompt
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
|
70 |
-
# Decode the generated tokens and remove the eos token
|
71 |
response = generate_response(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
with st.container():
|
74 |
-
st.markdown(f"**GPT-2**: {response}")
|
75 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
43 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
44 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
45 |
|
46 |
+
st.title("Echo Bot")
|
|
|
|
|
|
|
|
|
47 |
|
48 |
# Initialize chat history
|
49 |
if "messages" not in st.session_state:
|
|
|
51 |
|
52 |
# Display chat messages from history on app rerun
|
53 |
for message in st.session_state.messages:
|
54 |
+
with st.chat_message(message["role"]):
|
55 |
+
st.markdown(message["content"])
|
56 |
|
57 |
# React to user input
|
58 |
+
if prompt := st.chat_input("What is up?"):
|
59 |
+
# Display user message in chat message container
|
60 |
+
st.chat_message("user").markdown(prompt)
|
61 |
+
# Add user message to chat history
|
62 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
|
|
|
|
63 |
|
|
|
64 |
response = generate_response(prompt)
|
65 |
+
# Display assistant response in chat message container
|
66 |
+
with st.chat_message("assistant"):
|
67 |
+
st.markdown(response)
|
68 |
+
# Add assistant response to chat history
|
69 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
70 |
+
|
71 |
+
|
72 |
|
|
|
|
|
|