bluenevus commited on
Commit
64ae49b
·
1 Parent(s): 8695ba2

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -8,7 +8,7 @@ import tempfile
8
  import glob
9
  from flask import Flask, request as flask_request, make_response
10
  import dash
11
- from dash import dcc, html, Input, Output, State, callback_context
12
  import dash_bootstrap_components as dbc
13
  import openai
14
  import base64
@@ -458,6 +458,7 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
458
  )
459
  for i, chat in enumerate(chat_histories[-6:])
460
  ]
 
461
  return (
462
  upload_cards,
463
  chat_history_items,
@@ -465,7 +466,7 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
465
  "",
466
  True,
467
  0,
468
- user_input if user_input is not None else "",
469
  history_index_clicked
470
  )
471
 
@@ -717,6 +718,7 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
717
  )
718
  for i, chat in enumerate(state.get("chat_histories", [])[-6:])
719
  ]
 
720
  return (
721
  upload_cards,
722
  chat_history_items,
@@ -724,7 +726,7 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
724
  "",
725
  False,
726
  stream_n+1,
727
- user_input if user_input is not None else "",
728
  selected_history
729
  )
730
  else:
@@ -744,6 +746,7 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
744
  )
745
  for i, chat in enumerate(state.get("chat_histories", [])[-6:])
746
  ]
 
747
  return (
748
  upload_cards,
749
  chat_history_items,
@@ -751,7 +754,7 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
751
  "",
752
  True,
753
  0,
754
- user_input if user_input is not None else "",
755
  selected_history
756
  )
757
 
@@ -780,9 +783,10 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
780
  elif trigger == "new-chat-btn":
781
  return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, "", selected_history
782
  elif trigger == "file-upload":
783
- return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, user_input if user_input is not None else "", selected_history
 
784
  else:
785
- return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, user_input if user_input is not None else "", selected_history
786
 
787
  @app_flask.after_request
788
  def set_session_cookie(resp):
 
8
  import glob
9
  from flask import Flask, request as flask_request, make_response
10
  import dash
11
+ from dash import dcc, html, Input, Output, State, callback_context, no_update
12
  import dash_bootstrap_components as dbc
13
  import openai
14
  import base64
 
458
  )
459
  for i, chat in enumerate(chat_histories[-6:])
460
  ]
461
+ # Don't clear user input on chat history load; keep value unchanged
462
  return (
463
  upload_cards,
464
  chat_history_items,
 
466
  "",
467
  True,
468
  0,
469
+ no_update,
470
  history_index_clicked
471
  )
472
 
 
718
  )
719
  for i, chat in enumerate(state.get("chat_histories", [])[-6:])
720
  ]
721
+ # Don't clear user input during streaming refresh; keep value unchanged
722
  return (
723
  upload_cards,
724
  chat_history_items,
 
726
  "",
727
  False,
728
  stream_n+1,
729
+ no_update,
730
  selected_history
731
  )
732
  else:
 
746
  )
747
  for i, chat in enumerate(state.get("chat_histories", [])[-6:])
748
  ]
749
+ # Don't clear user input after streaming ends; keep value unchanged
750
  return (
751
  upload_cards,
752
  chat_history_items,
 
754
  "",
755
  True,
756
  0,
757
+ no_update,
758
  selected_history
759
  )
760
 
 
783
  elif trigger == "new-chat-btn":
784
  return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, "", selected_history
785
  elif trigger == "file-upload":
786
+ # Do not clear or update user input when a file is uploaded!
787
+ return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, no_update, selected_history
788
  else:
789
+ return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, no_update, selected_history
790
 
791
  @app_flask.after_request
792
  def set_session_cookie(resp):