bluenevus commited on
Commit
416a567
·
1 Parent(s): 64ae49b

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -598,6 +598,28 @@ def main_callback(session_id, send_clicks, file_contents, new_chat_clicks, strea
598
  threading.Thread(target=run_stream_for_doc, args=(session_id, list(state["messages"]), doc_question), daemon=True).start()
599
  start_streaming = True
600
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  send_triggered = False
602
  if trigger == "send-btn" or trigger == "hidden-send":
603
  send_triggered = True
 
598
  threading.Thread(target=run_stream_for_doc, args=(session_id, list(state["messages"]), doc_question), daemon=True).start()
599
  start_streaming = True
600
 
601
+ # After file upload (regardless of doc or image), DO NOT clear the user-input box, i.e. always return no_update below
602
+ chat_history = state.get("messages", [])
603
+ uploads = state.get("uploads", [])
604
+ chat_histories = state.get("chat_histories", [])
605
+ upload_cards = [uploaded_file_card(os.path.basename(f["name"]), f["is_img"]) for f in uploads]
606
+ chat_history_items = [
607
+ html.Li(
608
+ dbc.Button(
609
+ chat["name"],
610
+ id={"type": "chat-history-item", "index": i},
611
+ color="tertiary",
612
+ outline=False,
613
+ style={"width": "100%", "textAlign": "left", "fontWeight": "bold" if i == len(chat_histories)-1 else "normal", "fontSize": "0.92rem", "marginBottom": "0.2rem"}
614
+ )
615
+ )
616
+ for i, chat in enumerate(chat_histories[-6:])
617
+ ]
618
+ chat_cards = []
619
+ for msg in chat_history:
620
+ chat_cards.append(chat_message_card(msg['content'], is_user=(msg['role'] == "user")))
621
+ return upload_cards, chat_history_items, chat_cards, error, (not state.get("streaming", False)), 0, no_update, selected_history
622
+
623
  send_triggered = False
624
  if trigger == "send-btn" or trigger == "hidden-send":
625
  send_triggered = True