KhantKyaw commited on
Commit
93e9f31
·
verified ·
1 Parent(s): a85678b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -44,38 +44,38 @@ 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
- st.title("Simple Streamlit Chatbot")
 
58
 
59
- # User input text box
60
- user_input = st.text_input("You: ", key="user_input")
 
61
 
62
- # Button to send the message
63
- if st.button("Send"):
64
- # Generating a response
65
- response = get_response(user_input)
66
-
67
- # Displaying the conversation
68
- # Here, we use st.session_state to keep track of the conversation
69
- if 'conversation' not in st.session_state:
70
- st.session_state.conversation = []
71
 
72
- # Append the user input and bot response to the conversation
73
- st.session_state.conversation.append("You: " + user_input)
74
- st.session_state.conversation.append("Bot: " + response)
75
 
76
- # Display each line in the conversation
77
- for line in st.session_state.conversation:
78
- st.text(line)
79
 
80
 
81
 
 
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
+ # Set the title of the web app
58
+ st.title("Simple Chatbot")
59
 
60
+ # Initialize session state to store chat history
61
+ if 'chat_history' not in st.session_state:
62
+ st.session_state.chat_history = []
63
 
64
+ # Chat input
65
+ user_input = st.chat_input("You", key="chat_input")
66
+
67
+ # Check if there is an input
68
+ if user_input:
69
+ # Generate a response based on the user input
70
+ response = generate_response(user_input)
 
 
71
 
72
+ # Update chat history with the user input and bot response
73
+ st.session_state.chat_history.append(("You", user_input))
74
+ st.session_state.chat_history.append(("Bot", response))
75
 
76
+ # Display chat history
77
+ for author, text in st.session_state.chat_history:
78
+ st.chat_message(text=text, author=author)
79
 
80
 
81