milwright commited on
Commit
430b464
·
1 Parent(s): 189c33c

Fix export button functionality in deployment packages

Browse files

- Fix chat history storage in store_and_generate_response function
- Properly convert Gradio tuple format to dictionary format for export
- Eliminate duplicate history entries in exported conversations
- Ensure export button works correctly in generated spaces

Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -578,13 +578,19 @@ def store_and_generate_response(message, history):
578
  \"\"\"Wrapper function that stores history and generates response\"\"\"
579
  global chat_history_store
580
 
581
- # Store the updated history
582
- chat_history_store = history.copy() if history else []
583
-
584
  # Generate response using the protected function
585
  response = protected_generate_response(message, history)
586
 
587
- # Update stored history with the new exchange
 
 
 
 
 
 
 
 
 
588
  chat_history_store.append({{"role": "user", "content": message}})
589
  chat_history_store.append({{"role": "assistant", "content": response}})
590
 
 
578
  \"\"\"Wrapper function that stores history and generates response\"\"\"
579
  global chat_history_store
580
 
 
 
 
581
  # Generate response using the protected function
582
  response = protected_generate_response(message, history)
583
 
584
+ # Convert current history to the format we need for export
585
+ # history comes in as [["user1", "bot1"], ["user2", "bot2"], ...]
586
+ chat_history_store = []
587
+ if history:
588
+ for exchange in history:
589
+ if isinstance(exchange, (list, tuple)) and len(exchange) >= 2:
590
+ chat_history_store.append({{"role": "user", "content": exchange[0]}})
591
+ chat_history_store.append({{"role": "assistant", "content": exchange[1]}})
592
+
593
+ # Add the current exchange
594
  chat_history_store.append({{"role": "user", "content": message}})
595
  chat_history_store.append({{"role": "assistant", "content": response}})
596