Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -43,33 +43,33 @@ model_name = 'KhantKyaw/Chat_GPT-2'
|
|
43 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
44 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
45 |
|
46 |
-
# Chat loop
|
47 |
-
#print("Chatbot is ready. Type 'quit' to exit.")
|
48 |
-
#while True:
|
49 |
-
#user_input = input("You: ")
|
50 |
-
#if user_input.lower() == "quit":
|
51 |
-
#break
|
52 |
-
#response = generate_response(user_input)
|
53 |
-
#print("Chatbot:", response)
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
-
|
59 |
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
61 |
with st.container():
|
62 |
-
|
63 |
-
st.markdown(prompt)
|
64 |
-
|
65 |
-
# Generating and displaying the response.
|
66 |
-
response = generate_response(prompt)
|
67 |
-
st.markdown(generate_response(prompt))
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
# st.write(generate_response(prompt))
|
|
|
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:
|
54 |
+
st.session_state.messages = []
|
55 |
+
|
56 |
+
# Display chat messages from history on app rerun
|
57 |
+
for message in st.session_state.messages:
|
58 |
with st.container():
|
59 |
+
st.markdown(f"**{message['role'].capitalize()}**: {message['content']}")
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
# React to user input
|
62 |
+
prompt = st.text_input("What is up?", key="chat_input")
|
63 |
+
if prompt:
|
64 |
+
with st.container():
|
65 |
+
st.markdown(f"**User**: {prompt}")
|
66 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
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})
|
|