Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -174,37 +174,47 @@ def left_navbar_static():
|
|
174 |
html.Ul(id="chat-history-list", style={"listStyle": "none", "paddingLeft": "0"}),
|
175 |
], style={"padding": "1rem", "backgroundColor": "#f8f9fa", "height": "100vh", "overflowY": "auto"})
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
def right_main_static():
|
178 |
return html.Div([
|
179 |
-
|
180 |
-
|
181 |
-
html.Div(id="chat-window", style={
|
182 |
-
"height": "60vh",
|
183 |
-
"overflowY": "auto",
|
184 |
-
"display": "flex",
|
185 |
-
"flexDirection": "column",
|
186 |
-
"justifyContent": "flex-end",
|
187 |
-
"backgroundColor": "#fff",
|
188 |
-
"padding": "0.5rem",
|
189 |
-
"borderRadius": "0.5rem"
|
190 |
-
}),
|
191 |
-
html.Div([
|
192 |
-
dcc.Textarea(
|
193 |
-
id="user-input",
|
194 |
-
placeholder="Type your question...",
|
195 |
-
style={"width": "100%", "height": "60px", "resize": "vertical", "wordWrap": "break-word"},
|
196 |
-
wrap="soft",
|
197 |
-
maxLength=1000,
|
198 |
-
autoFocus=True
|
199 |
-
),
|
200 |
-
html.Div([
|
201 |
-
dbc.Button("Send", id="send-btn", color="primary", className="mt-2 me-2", style={"minWidth": "100px"}),
|
202 |
-
dbc.Button("New Chat", id="new-chat-btn", color="secondary", className="mt-2", style={"minWidth": "110px"}),
|
203 |
-
], style={"float": "right", "display": "flex", "gap": "0.5rem"}),
|
204 |
-
], style={"marginTop": "1rem"}),
|
205 |
-
html.Div(id="error-message", style={"color": "#bb2124", "marginTop": "0.5rem"}),
|
206 |
-
])
|
207 |
-
], className="mt-3"),
|
208 |
dcc.Loading(id="loading", type="default", fullscreen=False, style={"position": "absolute", "top": "5%", "left": "50%"}),
|
209 |
dcc.Interval(id="stream-interval", interval=400, n_intervals=0, disabled=True, max_intervals=1000)
|
210 |
], style={"padding": "1rem", "backgroundColor": "#fff", "height": "100vh", "overflowY": "auto"})
|
@@ -430,27 +440,6 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
|
|
430 |
return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, ""
|
431 |
return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, user_input or ""
|
432 |
|
433 |
-
# Clientside callback for pressing Enter to send
|
434 |
-
app.clientside_callback(
|
435 |
-
"""
|
436 |
-
function(n_clicks) {
|
437 |
-
var ta = document.getElementById('user-input');
|
438 |
-
if (ta) {
|
439 |
-
ta.addEventListener('keydown', function(e) {
|
440 |
-
if (e.key === 'Enter' && !e.shiftKey) {
|
441 |
-
e.preventDefault();
|
442 |
-
var sendBtn = document.getElementById('send-btn');
|
443 |
-
if(sendBtn){sendBtn.click();}
|
444 |
-
}
|
445 |
-
}, {once: true});
|
446 |
-
}
|
447 |
-
return window.dash_clientside.no_update;
|
448 |
-
}
|
449 |
-
""",
|
450 |
-
Output('user-input', 'value'),
|
451 |
-
[Input('send-btn', 'n_clicks')]
|
452 |
-
)
|
453 |
-
|
454 |
@app_flask.after_request
|
455 |
def set_session_cookie(resp):
|
456 |
sid = flask_request.cookies.get("asktricare_session_id")
|
|
|
174 |
html.Ul(id="chat-history-list", style={"listStyle": "none", "paddingLeft": "0"}),
|
175 |
], style={"padding": "1rem", "backgroundColor": "#f8f9fa", "height": "100vh", "overflowY": "auto"})
|
176 |
|
177 |
+
def chat_box_card():
|
178 |
+
return dbc.Card(
|
179 |
+
dbc.CardBody([
|
180 |
+
html.Div(id="chat-window", style={
|
181 |
+
"height": "60vh",
|
182 |
+
"overflowY": "auto",
|
183 |
+
"display": "flex",
|
184 |
+
"flexDirection": "column",
|
185 |
+
"justifyContent": "flex-end",
|
186 |
+
"backgroundColor": "#fff",
|
187 |
+
"padding": "0.5rem",
|
188 |
+
"borderRadius": "0.5rem"
|
189 |
+
})
|
190 |
+
]),
|
191 |
+
className="mt-3"
|
192 |
+
)
|
193 |
+
|
194 |
+
def user_input_card():
|
195 |
+
return dbc.Card(
|
196 |
+
dbc.CardBody([
|
197 |
+
html.Div([
|
198 |
+
dcc.Textarea(
|
199 |
+
id="user-input",
|
200 |
+
placeholder="Type your question...",
|
201 |
+
style={"width": "100%", "height": "60px", "resize": "vertical", "wordWrap": "break-word"},
|
202 |
+
wrap="soft",
|
203 |
+
maxLength=1000
|
204 |
+
),
|
205 |
+
html.Div([
|
206 |
+
dbc.Button("Send", id="send-btn", color="primary", className="mt-2 me-2", style={"minWidth": "100px"}),
|
207 |
+
dbc.Button("New Chat", id="new-chat-btn", color="secondary", className="mt-2", style={"minWidth": "110px"}),
|
208 |
+
], style={"float": "right", "display": "flex", "gap": "0.5rem"}),
|
209 |
+
], style={"marginTop": "1rem"}),
|
210 |
+
html.Div(id="error-message", style={"color": "#bb2124", "marginTop": "0.5rem"}),
|
211 |
+
])
|
212 |
+
)
|
213 |
+
|
214 |
def right_main_static():
|
215 |
return html.Div([
|
216 |
+
chat_box_card(),
|
217 |
+
user_input_card(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
dcc.Loading(id="loading", type="default", fullscreen=False, style={"position": "absolute", "top": "5%", "left": "50%"}),
|
219 |
dcc.Interval(id="stream-interval", interval=400, n_intervals=0, disabled=True, max_intervals=1000)
|
220 |
], style={"padding": "1rem", "backgroundColor": "#fff", "height": "100vh", "overflowY": "auto"})
|
|
|
440 |
return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, ""
|
441 |
return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, user_input or ""
|
442 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
443 |
@app_flask.after_request
|
444 |
def set_session_cookie(resp):
|
445 |
sid = flask_request.cookies.get("asktricare_session_id")
|