Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -54,42 +54,57 @@ def launch_bot():
|
|
54 |
if "messages" not in st.session_state.keys():
|
55 |
st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
response = generate_response(user_input)
|
62 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
63 |
-
display_chat_messages()
|
64 |
-
|
65 |
-
# Display clickable buttons for example questions
|
66 |
-
print(len(st.session_state.messages))
|
67 |
-
if len(st.session_state.messages)<=2:
|
68 |
-
st.markdown("## Try these example questions:")
|
69 |
-
for question in cfg.examples:
|
70 |
-
if st.button(question):
|
71 |
-
prompt = question
|
72 |
-
process_user_input(prompt) # Function to process and display the user input and response
|
73 |
-
|
74 |
# Display chat messages
|
75 |
for message in st.session_state.messages:
|
76 |
with st.chat_message(message["role"]):
|
77 |
st.write(message["content"])
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
# User-provided prompt
|
80 |
-
if prompt := st.chat_input():
|
81 |
-
st.session_state.messages.append({"role": "user", "content": prompt})
|
82 |
-
with st.chat_message("user"):
|
83 |
-
st.write(prompt)
|
84 |
|
85 |
# Generate a new response if last message is not from assistant
|
86 |
-
if st.session_state.messages[-1]["role"] != "assistant":
|
87 |
-
with st.chat_message("assistant"):
|
88 |
-
with st.spinner("Thinking..."):
|
89 |
-
response = generate_response(prompt)
|
90 |
-
st.write(response)
|
91 |
-
message = {"role": "assistant", "content": response}
|
92 |
-
st.session_state.messages.append(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
if __name__ == "__main__":
|
95 |
launch_bot()
|
|
|
54 |
if "messages" not in st.session_state.keys():
|
55 |
st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]
|
56 |
|
57 |
+
if "messages" not in st.session_state:
|
58 |
+
st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]
|
59 |
+
st.session_state.first_round = True
|
60 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
# Display chat messages
|
62 |
for message in st.session_state.messages:
|
63 |
with st.chat_message(message["role"]):
|
64 |
st.write(message["content"])
|
65 |
|
66 |
+
if st.session_state.first_round:
|
67 |
+
st.markdown("**Example questions:**")
|
68 |
+
for example in cfg.examples:
|
69 |
+
if st.button(example):
|
70 |
+
prompt = example
|
71 |
+
st.session_state.first_round = False
|
72 |
+
process_prompt(prompt)
|
73 |
+
else:
|
74 |
+
if prompt := st.chat_input("Ask me anything..."):
|
75 |
+
process_prompt(prompt) # Process the user-provided prompt
|
76 |
+
|
77 |
+
|
78 |
+
# Display chat messages
|
79 |
+
# for message in st.session_state.messages:
|
80 |
+
# with st.chat_message(message["role"]):
|
81 |
+
# st.write(message["content"])
|
82 |
+
|
83 |
# User-provided prompt
|
84 |
+
# if prompt := st.chat_input():
|
85 |
+
# st.session_state.messages.append({"role": "user", "content": prompt})
|
86 |
+
# with st.chat_message("user"):
|
87 |
+
# st.write(prompt)
|
88 |
|
89 |
# Generate a new response if last message is not from assistant
|
90 |
+
# if st.session_state.messages[-1]["role"] != "assistant":
|
91 |
+
# with st.chat_message("assistant"):
|
92 |
+
# with st.spinner("Thinking..."):
|
93 |
+
# response = generate_response(prompt)
|
94 |
+
# st.write(response)
|
95 |
+
# message = {"role": "assistant", "content": response}
|
96 |
+
# st.session_state.messages.append(message)
|
97 |
+
|
98 |
+
|
99 |
+
def process_prompt(prompt):
|
100 |
+
# Your logic to process the prompt and generate response
|
101 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
102 |
+
with st.chat_message("assistant"):
|
103 |
+
with st.spinner("Thinking..."):
|
104 |
+
response = generate_response(prompt)
|
105 |
+
st.write(response)
|
106 |
+
message = {"role": "assistant", "content": response}
|
107 |
+
st.session_state.messages.append(message)
|
108 |
|
109 |
if __name__ == "__main__":
|
110 |
launch_bot()
|