andreska commited on
Commit
84e19e3
·
verified ·
1 Parent(s): 9f2fcba

Instanciate scrollable div before stream starts

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -34,16 +34,6 @@ st.markdown(
34
  unsafe_allow_html=True
35
  )
36
 
37
- st.text_input('Ask me a question', key='user_input', on_change=handle_submit)
38
- col1, col2 = st.columns(2)
39
-
40
- with col1:
41
- if st.button("Ask"):
42
- handle_submit()
43
-
44
- with col2:
45
- st.session_state.include_context = st.checkbox('Search in Help')
46
-
47
  def handle_submit():
48
  user_input = st.session_state.user_input
49
 
@@ -71,16 +61,27 @@ def handle_submit():
71
 
72
  answer = ""
73
  placeholder =st.empty()
 
74
  for chunk in response:
75
  answer += chunk['choices'][0]['delta']['content']
76
- placeholder.markdown(f'<div class="scrollable-div"><p><strong>Adrega AI:</strong> {answer}</p></div>', unsafe_allow_html=True)
77
- st.session_state.conversation = f"<p><strong>Adrega AI:</strong> {answer}</p>" + st.session_state.conversation
78
  else:
79
  st.session_state.conversation(f"<p><strong>Adrega AI:</strong>: Please enter a question.")
80
 
81
  #st.title("Adrega AI Help")
82
 
 
 
 
 
 
 
 
83
  if 'conversation' not in st.session_state:
84
  st.session_state.conversation = ""
 
 
 
85
 
86
  #st.markdown(f'<div class="scrollable-div">{st.session_state.conversation}</div>', unsafe_allow_html=True)
 
34
  unsafe_allow_html=True
35
  )
36
 
 
 
 
 
 
 
 
 
 
 
37
  def handle_submit():
38
  user_input = st.session_state.user_input
39
 
 
61
 
62
  answer = ""
63
  placeholder =st.empty()
64
+ placeholder.markdown('<div class="scrollable-div"></div>', unsafe_allow_html=True)
65
  for chunk in response:
66
  answer += chunk['choices'][0]['delta']['content']
67
+ placeholder.markdown(f'<div class="scrollable-div"><p>{answer}</p></div>', unsafe_allow_html=True)
68
+ st.session_state.conversation = f"<p>{answer}</p>" + st.session_state.conversation
69
  else:
70
  st.session_state.conversation(f"<p><strong>Adrega AI:</strong>: Please enter a question.")
71
 
72
  #st.title("Adrega AI Help")
73
 
74
+ st.text_input('Ask me a question', key='user_input', on_change=handle_submit)
75
+ col1, col2 = st.columns(2)
76
+
77
+ with col1:
78
+ if st.button("Ask"):
79
+ handle_submit()
80
+
81
  if 'conversation' not in st.session_state:
82
  st.session_state.conversation = ""
83
+
84
+ with col2:
85
+ st.session_state.include_context = st.checkbox('Search in Help')
86
 
87
  #st.markdown(f'<div class="scrollable-div">{st.session_state.conversation}</div>', unsafe_allow_html=True)