Chris4K commited on
Commit
df2fd84
·
verified ·
1 Parent(s): 7c6b70c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -44
app.py CHANGED
@@ -531,45 +531,88 @@ if __name__ == "__main__":
531
  outputs=model_3d_output
532
  )
533
 
534
- # Examples with error handling
535
  try:
536
  examples_list = get_sorted_3d_model_examples()
537
  if examples_list:
538
- gr.Examples(
539
- label="Example 3D Models",
540
- examples=examples_list,
541
- inputs=model_3d_upload_button,
542
- outputs=model_3d_output,
543
- fn=load_mesh,
544
- cache_examples=False
545
- )
 
 
 
 
 
 
 
 
546
  except Exception as e:
547
  logger.error(f"Error setting up 3D model examples: {e}")
548
 
549
- # Chat interface setup
550
  with gr.Row():
551
  multimodal = False
552
- textbox_component = gr.MultimodalTextbox if multimodal else gr.Textbox
553
 
554
- textbox = textbox_component(
555
- show_label=False,
556
- label="Message",
557
- placeholder="Type a message...",
558
- scale=1,
559
- autofocus=True,
560
- submit_btn=True,
561
- stop_btn=True,
562
- elem_id="chat-textbox",
563
- lines=1,
564
- )
565
- chatbot = gr.Chatbot(
566
- type="messages",
567
- scale=0,
568
- show_copy_button=True,
569
- height=400,
570
- editable="all",
571
- elem_classes="main-chatbox"
572
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
573
 
574
  # Follow-up question buttons
575
  with gr.Row():
@@ -714,25 +757,38 @@ if __name__ == "__main__":
714
  outputs=[current_langgraph_state, current_uuid_state]
715
  )
716
 
717
- # Main chat interface
718
- chat_interface = gr.ChatInterface(
719
- chatbot=chatbot,
720
- fn=chat_fn,
721
- additional_inputs=[
722
  current_langgraph_state,
723
  current_uuid_state,
724
  prompt_textbox,
725
  checkbox_search_enabled,
726
  checkbox_download_website_text,
727
  ],
728
- additional_outputs=[
729
  current_langgraph_state,
730
  end_of_assistant_response_state
731
  ],
732
- type="messages",
733
- multimodal=multimodal,
734
- textbox=textbox,
735
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
736
 
737
  # New chat button functionality
738
  new_chat_button.click(
@@ -771,8 +827,19 @@ if __name__ == "__main__":
771
  ]
772
  ).success(lambda: None, js=TRIGGER_CHATINTERFACE_BUTTON)
773
 
774
- # Event handlers for chatbot changes
775
- chatbot.change(
 
 
 
 
 
 
 
 
 
 
 
776
  fn=populate_followup_questions,
777
  inputs=[
778
  end_of_assistant_response_state,
@@ -786,7 +853,7 @@ if __name__ == "__main__":
786
  trigger_mode="multiple"
787
  )
788
 
789
- chatbot.change(
790
  fn=summarize_chat,
791
  inputs=[
792
  end_of_assistant_response_state,
@@ -801,7 +868,7 @@ if __name__ == "__main__":
801
  trigger_mode="multiple"
802
  )
803
 
804
- chatbot.change(
805
  fn=lambda x: x,
806
  inputs=[chatbot],
807
  outputs=[chatbot_message_storage],
 
531
  outputs=model_3d_output
532
  )
533
 
534
+ # Examples with error handling and version compatibility
535
  try:
536
  examples_list = get_sorted_3d_model_examples()
537
  if examples_list:
538
+ examples_kwargs = {
539
+ "label": "Example 3D Models",
540
+ "examples": examples_list,
541
+ "inputs": model_3d_upload_button,
542
+ "outputs": model_3d_output,
543
+ "fn": load_mesh,
544
+ }
545
+
546
+ # Check if cache_examples parameter is supported
547
+ try:
548
+ if 'cache_examples' in gr.Examples.__init__.__code__.co_varnames:
549
+ examples_kwargs["cache_examples"] = False
550
+ except:
551
+ pass
552
+
553
+ gr.Examples(**examples_kwargs)
554
  except Exception as e:
555
  logger.error(f"Error setting up 3D model examples: {e}")
556
 
557
+ # Chat interface setup - with compatibility checks
558
  with gr.Row():
559
  multimodal = False
 
560
 
561
+ # Check if MultimodalTextbox is available
562
+ if hasattr(gr, 'MultimodalTextbox') and multimodal:
563
+ textbox_component = gr.MultimodalTextbox
564
+ else:
565
+ textbox_component = gr.Textbox
566
+ multimodal = False # Force to False if not available
567
+
568
+ textbox_kwargs = {
569
+ "show_label": False,
570
+ "label": "Message",
571
+ "placeholder": "Type a message...",
572
+ "scale": 1,
573
+ "elem_id": "chat-textbox",
574
+ "lines": 1,
575
+ }
576
+
577
+ # Check if newer textbox parameters are supported
578
+ try:
579
+ if 'autofocus' in textbox_component.__init__.__code__.co_varnames:
580
+ textbox_kwargs["autofocus"] = True
581
+ if 'submit_btn' in textbox_component.__init__.__code__.co_varnames:
582
+ textbox_kwargs["submit_btn"] = True
583
+ if 'stop_btn' in textbox_component.__init__.__code__.co_varnames:
584
+ textbox_kwargs["stop_btn"] = True
585
+ except Exception as e:
586
+ logger.warning(f"Error checking textbox parameters: {e}")
587
+
588
+ textbox = textbox_component(**textbox_kwargs)
589
+ # Check if newer Chatbot parameters are supported
590
+ chatbot_kwargs = {
591
+ "height": 400,
592
+ "elem_classes": "main-chatbox"
593
+ }
594
+
595
+ # Add parameters that might not be available in older versions
596
+ try:
597
+ # Try to create a test chatbot to see what parameters are supported
598
+ test_chatbot = gr.Chatbot()
599
+
600
+ # Check if 'type' parameter is supported
601
+ if hasattr(test_chatbot, 'type') or 'type' in gr.Chatbot.__init__.__code__.co_varnames:
602
+ chatbot_kwargs["type"] = "messages"
603
+
604
+ # Check if 'show_copy_button' parameter is supported
605
+ if 'show_copy_button' in gr.Chatbot.__init__.__code__.co_varnames:
606
+ chatbot_kwargs["show_copy_button"] = True
607
+
608
+ # Check if 'scale' parameter is supported
609
+ if 'scale' in gr.Chatbot.__init__.__code__.co_varnames:
610
+ chatbot_kwargs["scale"] = 0
611
+
612
+ except Exception as e:
613
+ logger.warning(f"Error checking Chatbot parameters: {e}")
614
+
615
+ chatbot = gr.Chatbot(**chatbot_kwargs)
616
 
617
  # Follow-up question buttons
618
  with gr.Row():
 
757
  outputs=[current_langgraph_state, current_uuid_state]
758
  )
759
 
760
+ # Main chat interface - with compatibility checks
761
+ chat_interface_kwargs = {
762
+ "chatbot": chatbot,
763
+ "fn": chat_fn,
764
+ "additional_inputs": [
765
  current_langgraph_state,
766
  current_uuid_state,
767
  prompt_textbox,
768
  checkbox_search_enabled,
769
  checkbox_download_website_text,
770
  ],
771
+ "additional_outputs": [
772
  current_langgraph_state,
773
  end_of_assistant_response_state
774
  ],
775
+ "textbox": textbox,
776
+ }
777
+
778
+ # Check if newer ChatInterface parameters are supported
779
+ try:
780
+ # Check if 'type' parameter is supported
781
+ if 'type' in gr.ChatInterface.__init__.__code__.co_varnames:
782
+ chat_interface_kwargs["type"] = "messages"
783
+
784
+ # Check if 'multimodal' parameter is supported
785
+ if 'multimodal' in gr.ChatInterface.__init__.__code__.co_varnames:
786
+ chat_interface_kwargs["multimodal"] = multimodal
787
+
788
+ except Exception as e:
789
+ logger.warning(f"Error checking ChatInterface parameters: {e}")
790
+
791
+ chat_interface = gr.ChatInterface(**chat_interface_kwargs)
792
 
793
  # New chat button functionality
794
  new_chat_button.click(
 
827
  ]
828
  ).success(lambda: None, js=TRIGGER_CHATINTERFACE_BUTTON)
829
 
830
+ # Event handlers for chatbot changes - with compatibility checks
831
+ def setup_change_handler(fn, inputs, outputs, trigger_mode=None):
832
+ """Helper function to set up change handlers with optional trigger_mode"""
833
+ try:
834
+ if trigger_mode and 'trigger_mode' in chatbot.change.__code__.co_varnames:
835
+ return chatbot.change(fn=fn, inputs=inputs, outputs=outputs, trigger_mode=trigger_mode)
836
+ else:
837
+ return chatbot.change(fn=fn, inputs=inputs, outputs=outputs)
838
+ except Exception as e:
839
+ logger.warning(f"Error setting up change handler: {e}")
840
+ return chatbot.change(fn=fn, inputs=inputs, outputs=outputs)
841
+
842
+ setup_change_handler(
843
  fn=populate_followup_questions,
844
  inputs=[
845
  end_of_assistant_response_state,
 
853
  trigger_mode="multiple"
854
  )
855
 
856
+ setup_change_handler(
857
  fn=summarize_chat,
858
  inputs=[
859
  end_of_assistant_response_state,
 
868
  trigger_mode="multiple"
869
  )
870
 
871
+ setup_change_handler(
872
  fn=lambda x: x,
873
  inputs=[chatbot],
874
  outputs=[chatbot_message_storage],