venkat charan commited on
Commit
66f912f
·
verified ·
1 Parent(s): 8c20aaa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -29,19 +29,26 @@ st.write("Enter your input text:")
29
  # User input
30
  user_input = st.text_area("Input Text")
31
 
 
 
 
 
 
 
 
32
  # Generate and display the response
33
- if st.button("Generate Response"):
34
  # Load current conversation history
35
- history = memory.load_memory_variables({})['history']
36
 
37
  # Invoke the chain to get the response
38
- res = chain.invoke({"input": user_input})
39
- response_content = res.content
40
- st.write("Generated Response:")
41
- st.write(response_content)
42
 
43
  # Save the context in memory
44
- memory.save_context({"input": user_input}, {"output": response_content})
45
 
46
  # Display the conversation history
47
  #st.write("Conversation History:")
@@ -49,8 +56,7 @@ if st.button("Generate Response"):
49
  # st.write(f"{msg['role']}: {msg['content']}")
50
 
51
  # Optionally, you can also add a button to reset the conversation history
52
- if st.button("End Conversation"):
53
- st.write("Conversation ended.")
54
- memory.clear()
55
 
56
 
 
29
  # User input
30
  user_input = st.text_area("Input Text")
31
 
32
+ def end_conv():
33
+ if st.button("End Conversation"):
34
+ st.write("Conversation ended.")
35
+ memory.clear()
36
+
37
+ while st.button("End Conversation")!=True:
38
+ user_input = st.text_area("Input Text")
39
  # Generate and display the response
40
+ if st.button("Generate Response"):
41
  # Load current conversation history
42
+ history = memory.load_memory_variables({})['history']
43
 
44
  # Invoke the chain to get the response
45
+ res = chain.invoke({"input": user_input})
46
+ response_content = res.content
47
+ st.write("Generated Response:")
48
+ st.write(response_content)
49
 
50
  # Save the context in memory
51
+ memory.save_context({"input": user_input}, {"output": response_content})
52
 
53
  # Display the conversation history
54
  #st.write("Conversation History:")
 
56
  # st.write(f"{msg['role']}: {msg['content']}")
57
 
58
  # Optionally, you can also add a button to reset the conversation history
59
+ if st.button("End Conversation"):
60
+ end_conv()
 
61
 
62