andreska commited on
Commit
e304e83
·
verified ·
1 Parent(s): 70762ea

Try to make Gemini fix the problem with reinstantiated scrollable div

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -23,12 +23,12 @@ context = read_dataset(dataset)
23
  st.markdown(
24
  """
25
  <style>
26
- .scrollable-div {
27
- height: 400px;
28
  width: 100%;
29
- overflow-y: auto;
30
- padding: 10px;
31
- border: 1px solid #ccc;
32
  }
33
  </style>
34
  """,
@@ -59,31 +59,28 @@ def handle_submit():
59
  max_tokens=1000,
60
  stream=True
61
  )
62
-
63
  answer = ""
64
- placeholder = st.session_state.placeholder
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
  if 'placeholder' not in st.session_state:
73
- st.session_state.placeholder = st.empty()
74
 
75
  st.text_input('Ask me a question', key='user_input', on_change=handle_submit)
76
  col1, col2 = st.columns(2)
77
 
78
- with col1:
79
- if st.button("Ask"):
80
  handle_submit()
81
 
82
  if 'conversation' not in st.session_state:
83
  st.session_state.conversation = ""
84
 
85
  with col2:
86
- st.session_state.include_context = st.checkbox('Search in Help')
87
-
88
- #st.session_state.placeholder
89
- #st.markdown(f'<div class="scrollable-div">{st.session_state.conversation}</div>', unsafe_allow_html=True)
 
23
  st.markdown(
24
  """
25
  <style>
26
+ .scrollable-div {
27
+ height: 400px;
28
  width: 100%;
29
+ overflow-y: auto;
30
+ padding: 10px;
31
+ border: 1px solid #ccc;
32
  }
33
  </style>
34
  """,
 
59
  max_tokens=1000,
60
  stream=True
61
  )
62
+
63
  answer = ""
64
+ for chunk in response:
65
+ answer += chunk['choices'][0]['delta']['content']
66
+ placeholder.markdown(f'<div class="scrollable-div"><p>{answer}</p></div>', unsafe_allow_html=True)
67
+ st.session_state.conversation = f"<p>{answer}</p>" + st.session_state.conversation
 
68
  else:
69
  st.session_state.conversation(f"<p><strong>Adrega AI:</strong>: Please enter a question.")
70
 
71
+ # Create the placeholder element only once
72
  if 'placeholder' not in st.session_state:
73
+ placeholder = st.session_state.placeholder = st.empty()
74
 
75
  st.text_input('Ask me a question', key='user_input', on_change=handle_submit)
76
  col1, col2 = st.columns(2)
77
 
78
+ with col1:
79
+ if st.button("Ask"):
80
  handle_submit()
81
 
82
  if 'conversation' not in st.session_state:
83
  st.session_state.conversation = ""
84
 
85
  with col2:
86
+ st.session_state.include_context = st.checkbox('Search in Help')