milwright commited on
Commit
5a8f506
·
1 Parent(s): d68f6d0

fix export conversation bug and update gradio to 5.42.0

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -1
  2. space_template.py +27 -15
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==5.37.0
2
  requests>=2.32.3
3
  beautifulsoup4>=4.12.3
4
  python-dotenv>=1.0.0
 
1
+ gradio>=5.42.0
2
  requests>=2.32.3
3
  beautifulsoup4>=4.12.3
4
  python-dotenv>=1.0.0
space_template.py CHANGED
@@ -589,34 +589,46 @@ def create_interface():
589
 
590
  # Export functionality
591
  with gr.Row():
592
- export_btn = gr.DownloadButton(
 
593
  "📥 Export Conversation",
594
  variant="secondary",
595
  size="sm"
596
  )
 
 
 
 
 
597
 
598
  # Export handler
599
  def prepare_export(chat_history):
600
  if not chat_history:
 
601
  return None
602
 
603
- content = export_conversation_to_markdown(chat_history)
604
-
605
- # Create filename
606
- space_name_safe = re.sub(r'[^a-zA-Z0-9]+', '_', SPACE_NAME).lower()
607
- timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
608
- filename = f"{{space_name_safe}}_conversation_{{timestamp}}.md"
609
-
610
- # Save to temp file
611
- temp_path = Path(tempfile.gettempdir()) / filename
612
- temp_path.write_text(content, encoding='utf-8')
613
-
614
- return str(temp_path)
 
 
 
 
 
615
 
616
- export_btn.click(
617
  prepare_export,
618
  inputs=[chatbot],
619
- outputs=[export_btn]
620
  )
621
 
622
  # Examples section
 
589
 
590
  # Export functionality
591
  with gr.Row():
592
+ # Use a regular Button for triggering export
593
+ export_trigger_btn = gr.Button(
594
  "📥 Export Conversation",
595
  variant="secondary",
596
  size="sm"
597
  )
598
+ # Hidden file component for actual download
599
+ export_file = gr.File(
600
+ visible=False,
601
+ label="Download Export"
602
+ )
603
 
604
  # Export handler
605
  def prepare_export(chat_history):
606
  if not chat_history:
607
+ gr.Warning("No conversation history to export.")
608
  return None
609
 
610
+ try:
611
+ content = export_conversation_to_markdown(chat_history)
612
+
613
+ # Create filename
614
+ space_name_safe = re.sub(r'[^a-zA-Z0-9]+', '_', SPACE_NAME).lower()
615
+ timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
616
+ filename = f"{{space_name_safe}}_conversation_{{timestamp}}.md"
617
+
618
+ # Save to temp file
619
+ temp_path = Path(tempfile.gettempdir()) / filename
620
+ temp_path.write_text(content, encoding='utf-8')
621
+
622
+ # Return the file component with visibility and value
623
+ return gr.File(visible=True, value=str(temp_path))
624
+ except Exception as e:
625
+ gr.Error(f"Failed to export conversation: {{str(e)}}")
626
+ return None
627
 
628
+ export_trigger_btn.click(
629
  prepare_export,
630
  inputs=[chatbot],
631
+ outputs=[export_file]
632
  )
633
 
634
  # Examples section