JohnAlexander23 commited on
Commit
c5618a4
·
verified ·
1 Parent(s): eddb11d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -31
app.py CHANGED
@@ -55,24 +55,15 @@ st.markdown(
55
  font-size: 1.2rem;
56
  margin-top: 1rem;
57
  }
58
- .stTextInput>div>div>input {
59
- background: linear-gradient(145deg, #5e5e87, #4a4a6c);
60
- box-shadow: inset 8px 8px 16px #29293f, inset -8px -8px 16px #3a3a56;
61
- border: none;
62
- border-radius: 12px;
63
- color: #e1e1e1;
64
- padding: 1rem;
65
- font-size: 1rem;
66
- }
67
  .chat-container {
68
- padding-bottom: 50px;
69
  }
70
  .chat-input {
71
  position: fixed;
72
  bottom: 0;
73
  left: 50%;
74
  transform: translateX(-50%);
75
- width: 50%;
76
  background: linear-gradient(145deg, #5e5e87, #4a4a6c);
77
  box-shadow: inset 8px 8px 16px #29293f, inset -8px -8px 16px #3a3a56;
78
  border: none;
@@ -80,6 +71,25 @@ st.markdown(
80
  color: #e1e1e1;
81
  padding: 1rem;
82
  font-size: 1rem;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  }
84
  .previous-sessions {
85
  color: #e1e1e1;
@@ -90,6 +100,18 @@ st.markdown(
90
  text-align: right;
91
  margin-top: 2rem;
92
  }
 
 
 
 
 
 
 
 
 
 
 
 
93
  </style>
94
  """,
95
  unsafe_allow_html=True
@@ -115,35 +137,45 @@ for chat in st.session_state.chat_history:
115
  st.markdown(f"**AI:** {chat['content']}")
116
  st.markdown("</div>", unsafe_allow_html=True)
117
 
118
- # Text input for user's question
119
- user_input = st.text_input("Enter your question here:", key="input", label_visibility='collapsed', placeholder='Type your message here...')
120
-
121
- # Button to trigger response
122
- if st.button("Get Response", key="get_response"):
123
- if user_input:
124
- # Fetch and display response
125
- fetch_response(user_input)
126
- st.experimental_rerun()
127
-
128
- # Save session state when user leaves
129
- if st.button("Save Session"):
130
- st.session_state.previous_sessions.append(st.session_state.chat_history)
131
- st.session_state.chat_history = [
132
- {"role": "system", "content": "you are a helpful assistant. Take the input from the users and try to provide as detailed response as possible. Provide proper examples to help the user. Try to mention references or provide citations to make it more detail-oriented."}
133
- ]
134
- st.experimental_rerun()
135
-
136
- # Display the permanent input field at the bottom center
137
  st.markdown(
138
  """
139
  <div class="chat-input">
140
  <input type="text" id="chat-input-field" placeholder="Type your message here..." onkeydown="if(event.key === 'Enter'){document.getElementById('chat-submit-button').click();}">
141
- <button id="chat-submit-button" onclick="document.querySelector('button[kind=primary][key=get_response]').click();">Send</button>
142
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  """,
144
  unsafe_allow_html=True
145
  )
146
 
 
 
 
 
 
 
 
 
147
  # Footer
148
  st.markdown(
149
  """
@@ -156,3 +188,4 @@ st.markdown(
156
 
157
 
158
 
 
 
55
  font-size: 1.2rem;
56
  margin-top: 1rem;
57
  }
 
 
 
 
 
 
 
 
 
58
  .chat-container {
59
+ padding-bottom: 100px;
60
  }
61
  .chat-input {
62
  position: fixed;
63
  bottom: 0;
64
  left: 50%;
65
  transform: translateX(-50%);
66
+ width: 60%;
67
  background: linear-gradient(145deg, #5e5e87, #4a4a6c);
68
  box-shadow: inset 8px 8px 16px #29293f, inset -8px -8px 16px #3a3a56;
69
  border: none;
 
71
  color: #e1e1e1;
72
  padding: 1rem;
73
  font-size: 1rem;
74
+ display: flex;
75
+ align-items: center;
76
+ }
77
+ .chat-input input {
78
+ flex: 1;
79
+ background: transparent;
80
+ border: none;
81
+ color: inherit;
82
+ font-size: inherit;
83
+ padding: 0;
84
+ margin: 0;
85
+ }
86
+ .chat-input button {
87
+ background: transparent;
88
+ border: none;
89
+ color: inherit;
90
+ font-size: inherit;
91
+ margin-left: 1rem;
92
+ cursor: pointer;
93
  }
94
  .previous-sessions {
95
  color: #e1e1e1;
 
100
  text-align: right;
101
  margin-top: 2rem;
102
  }
103
+ .save-session {
104
+ position: fixed;
105
+ bottom: 10px;
106
+ right: 10px;
107
+ background: linear-gradient(145deg, #5e5e87, #4a4a6c);
108
+ box-shadow: 8px 8px 16px #29293f, -8px -8px 16px #3a3a56;
109
+ border: none;
110
+ border-radius: 12px;
111
+ color: #e1e1e1;
112
+ padding: 0.5rem 2rem;
113
+ font-size: 1rem;
114
+ }
115
  </style>
116
  """,
117
  unsafe_allow_html=True
 
137
  st.markdown(f"**AI:** {chat['content']}")
138
  st.markdown("</div>", unsafe_allow_html=True)
139
 
140
+ # Custom input field
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  st.markdown(
142
  """
143
  <div class="chat-input">
144
  <input type="text" id="chat-input-field" placeholder="Type your message here..." onkeydown="if(event.key === 'Enter'){document.getElementById('chat-submit-button').click();}">
145
+ <button id="chat-submit-button" onclick="sendChat()">Send</button>
146
  </div>
147
+ <script>
148
+ function sendChat() {
149
+ const inputField = document.getElementById('chat-input-field');
150
+ const message = inputField.value;
151
+ if (message) {
152
+ inputField.value = '';
153
+ fetch('/', {
154
+ method: 'POST',
155
+ headers: {
156
+ 'Content-Type': 'application/json'
157
+ },
158
+ body: JSON.stringify({ 'user_input': message })
159
+ }).then(response => {
160
+ if (response.ok) {
161
+ location.reload();
162
+ }
163
+ });
164
+ }
165
+ }
166
+ </script>
167
  """,
168
  unsafe_allow_html=True
169
  )
170
 
171
+ # Save session button
172
+ if st.button("Save Session", key="save_session", help="Save the current chat session", class_="save-session"):
173
+ st.session_state.previous_sessions.append(st.session_state.chat_history)
174
+ st.session_state.chat_history = [
175
+ {"role": "system", "content": "you are a helpful assistant. Take the input from the users and try to provide as detailed response as possible. Provide proper examples to help the user. Try to mention references or provide citations to make it more detail-oriented."}
176
+ ]
177
+ st.experimental_rerun()
178
+
179
  # Footer
180
  st.markdown(
181
  """
 
188
 
189
 
190
 
191
+