wishwakankanamg commited on
Commit
d58b4eb
·
1 Parent(s): 761a8b4

fixed the sidebar issue

Browse files
Files changed (4) hide show
  1. __pycache__/graph.cpython-313.pyc +0 -0
  2. app.log +42 -0
  3. app.py +250 -106
  4. setup.md +6 -0
__pycache__/graph.cpython-313.pyc CHANGED
Binary files a/__pycache__/graph.cpython-313.pyc and b/__pycache__/graph.cpython-313.pyc differ
 
app.log CHANGED
@@ -54842,3 +54842,45 @@ For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/er
54842
  2025-06-11 00:25:24:__main__:INFO: Starting the interface
54843
  2025-06-11 00:26:09:__main__:INFO: Starting the interface
54844
  2025-06-11 00:28:10:__main__:INFO: Starting the interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54842
  2025-06-11 00:25:24:__main__:INFO: Starting the interface
54843
  2025-06-11 00:26:09:__main__:INFO: Starting the interface
54844
  2025-06-11 00:28:10:__main__:INFO: Starting the interface
54845
+ 2025-06-25 07:58:26:__main__:INFO: Starting the interface
54846
+ 2025-06-25 07:58:53:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54847
+ 2025-06-25 07:59:44:__main__:INFO: Prompt: You are a helpful assistant.
54848
+ 2025-06-25 07:59:49:__main__:ERROR: Exception occurred
54849
+ Traceback (most recent call last):
54850
+ File "C:\_projects\huggingface_agents\mcp-hacthon\DIY_agent\version0.0.2\DIY_assistant\app.py", line 115, in chat_fn
54851
+ async for stream_mode, chunk in graph.astream(
54852
+ ...<56 lines>...
54853
+ yield output, gr.skip(), gr.skip()
54854
+ File "C:\_projects\huggingface_agents\mcp-hacthon\DIY_agent\version0.0.2\DIY_assistant\venv\Lib\site-packages\langgraph\pregel\__init__.py", line 2677, in astream
54855
+ raise GraphRecursionError(msg)
54856
+ langgraph.errors.GraphRecursionError: Recursion limit of 20 reached without hitting a stop condition. You can increase the limit by setting the `recursion_limit` config key.
54857
+ For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/GRAPH_RECURSION_LIMIT
54858
+ 2025-06-25 08:00:58:__main__:INFO: Prompt: You are a helpful assistant.
54859
+ 2025-06-25 08:01:24:__main__:INFO: Prompt: You are a helpful assistant.
54860
+ 2025-06-25 08:01:48:__main__:INFO: Prompt: You are a helpful assistant.
54861
+ 2025-06-25 08:02:22:__main__:INFO: Prompt: You are a helpful assistant.
54862
+ 2025-06-25 08:02:35:__main__:INFO: Prompt: You are a helpful assistant.
54863
+ 2025-06-25 08:03:34:__main__:ERROR: Exception occurred
54864
+ Traceback (most recent call last):
54865
+ File "C:\_projects\huggingface_agents\mcp-hacthon\DIY_agent\version0.0.2\DIY_assistant\app.py", line 115, in chat_fn
54866
+ async for stream_mode, chunk in graph.astream(
54867
+ ...<56 lines>...
54868
+ yield output, gr.skip(), gr.skip()
54869
+ File "C:\_projects\huggingface_agents\mcp-hacthon\DIY_agent\version0.0.2\DIY_assistant\venv\Lib\site-packages\langgraph\pregel\__init__.py", line 2677, in astream
54870
+ raise GraphRecursionError(msg)
54871
+ langgraph.errors.GraphRecursionError: Recursion limit of 20 reached without hitting a stop condition. You can increase the limit by setting the `recursion_limit` config key.
54872
+ For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/GRAPH_RECURSION_LIMIT
54873
+ 2025-06-26 07:52:38:__main__:INFO: Starting the interface
54874
+ 2025-06-26 07:53:03:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54875
+ 2025-06-26 08:07:53:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54876
+ 2025-06-26 08:08:07:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54877
+ 2025-06-26 08:08:16:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54878
+ 2025-06-26 08:08:34:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54879
+ 2025-06-26 08:09:15:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54880
+ 2025-06-26 08:09:33:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54881
+ 2025-06-26 08:09:48:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54882
+ 2025-06-26 08:09:50:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54883
+ 2025-06-26 08:10:13:__main__:INFO: Starting the interface
54884
+ 2025-06-26 08:10:16:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
54885
+ 2025-06-26 08:10:39:__main__:INFO: Prompt: You are a helpful assistant.
54886
+ 2025-06-26 08:10:51:__main__:INFO: Prompt: You are a helpful assistant.
app.py CHANGED
@@ -592,111 +592,62 @@ if __name__ == "__main__":
592
  str()
593
  )
594
  prompt_textbox.change(lambda prompt: prompt, inputs=[prompt_textbox], outputs=[current_prompt_state])
 
 
 
595
  with gr.Sidebar() as sidebar:
596
- @gr.render(inputs=[tab_edit_uuid_state, end_of_assistant_response_state, sidebar_names_state, current_uuid_state, chatbot, offloaded_tabs_data_storage])
597
- def render_chats(tab_uuid_edit, end_of_chat_response, sidebar_summaries, active_uuid, messages, tabs):
598
- current_tab_button_text = ""
599
- if active_uuid not in sidebar_summaries:
600
- current_tab_button_text = "Current Chat"
601
- elif active_uuid not in tabs:
602
- current_tab_button_text = sidebar_summaries[active_uuid]
603
- if current_tab_button_text:
604
- unique_id = f"current-tab-{active_uuid}-{uuid4()}"
605
- gr.Button(
606
- current_tab_button_text,
607
- elem_classes=["chat-tab", "active"],
608
- elem_id=unique_id # Add unique elem_id
609
- )
610
- for chat_uuid, tab in reversed(tabs.items()):
611
- elem_classes = ["chat-tab"]
612
- if chat_uuid == active_uuid:
613
- elem_classes.append("active")
614
- button_uuid_state = gr.State(chat_uuid)
615
- with gr.Row():
616
- clear_tab_button = gr.Button(
617
- "🗑",
618
- scale=0,
619
- elem_classes=["tab-button-control"],
620
- elem_id=f"delete-btn-{chat_uuid}-{uuid4()}" # Add unique ID
621
- )
622
- clear_tab_button.click(
623
- fn=delete_tab,
624
- inputs=[
625
- current_uuid_state,
626
- button_uuid_state,
627
- sidebar_names_state,
628
- offloaded_tabs_data_storage
629
- ],
630
- outputs=[
631
- sidebar_names_state,
632
- offloaded_tabs_data_storage,
633
- chat_interface.chatbot_value
634
- ]
635
- )
636
- chat_button_text = sidebar_summaries.get(chat_uuid)
637
- if not chat_button_text:
638
- chat_button_text = str(chat_uuid)
639
- if chat_uuid != tab_uuid_edit:
640
- set_edit_tab_button = gr.Button(
641
- "✎",
642
- scale=0,
643
- elem_classes=["tab-button-control"],
644
- elem_id=f"edit-btn-{chat_uuid}-{uuid4()}" # Add unique ID
645
- )
646
- set_edit_tab_button.click(
647
- fn=lambda x: x,
648
- inputs=[button_uuid_state],
649
- outputs=[tab_edit_uuid_state]
650
- )
651
- chat_tab_button = gr.Button(
652
- chat_button_text,
653
- elem_id=f"chat-{chat_uuid}-{uuid4()}", # Add truly unique ID
654
- elem_classes=elem_classes,
655
- scale=2
656
- )
657
- chat_tab_button.click(
658
- fn=switch_tab,
659
- inputs=[
660
- button_uuid_state,
661
- offloaded_tabs_data_storage,
662
- current_langgraph_state,
663
- current_uuid_state,
664
- chatbot,
665
- prompt_textbox
666
- ],
667
- outputs=[
668
- current_langgraph_state,
669
- current_uuid_state,
670
- chat_interface.chatbot_value,
671
- offloaded_tabs_data_storage,
672
- prompt_textbox,
673
- *followup_question_buttons
674
- ]
675
- )
676
- else:
677
- chat_tab_text = gr.Textbox(
678
- chat_button_text,
679
- scale=2,
680
- interactive=True,
681
- show_label=False,
682
- elem_id=f"edit-text-{chat_uuid}-{uuid4()}" # Add unique ID
683
- )
684
- chat_tab_text.submit(
685
- fn=submit_edit_tab,
686
- inputs=[
687
- button_uuid_state,
688
- sidebar_names_state,
689
- chat_tab_text
690
- ],
691
- outputs=[
692
- sidebar_names_state,
693
- tab_edit_uuid_state
694
- ]
695
- )
696
- # )
697
- # return chat_tabs, sidebar_summaries
698
  new_chat_button = gr.Button("New Chat", elem_id="new-chat-button")
699
- chatbot.clear(fn=clear, outputs=[current_langgraph_state, current_uuid_state])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
700
 
701
  chat_interface = gr.ChatInterface(
702
  chatbot=chatbot,
@@ -712,11 +663,204 @@ if __name__ == "__main__":
712
  current_langgraph_state,
713
  end_of_assistant_response_state
714
  ],
715
- type="messages",
716
  multimodal=multimodal,
717
  textbox=textbox,
718
  )
719
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720
  new_chat_button.click(
721
  new_tab,
722
  inputs=[
@@ -846,9 +990,9 @@ if __name__ == "__main__":
846
  return current_prompt
847
 
848
 
849
- # demo.launch(server_name="127.0.0.1", server_port=8080, share=True)
850
 
851
- demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
852
 
853
 
854
 
 
592
  str()
593
  )
594
  prompt_textbox.change(lambda prompt: prompt, inputs=[prompt_textbox], outputs=[current_prompt_state])
595
+
596
+ MAX_CHATS_IN_SIDEBAR = 25
597
+
598
  with gr.Sidebar() as sidebar:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
  new_chat_button = gr.Button("New Chat", elem_id="new-chat-button")
600
+
601
+ # --- This is the "Component Pool" ---
602
+ # We create a fixed number of rows for our chats and hide them initially.
603
+ sidebar_chat_rows = []
604
+ for i in range(MAX_CHATS_IN_SIDEBAR):
605
+ with gr.Row(visible=False, elem_classes="chat-tab-row") as row:
606
+ # We need a gr.State to hold the unique ID for each chat in the list
607
+ chat_id_state = gr.State()
608
+
609
+ # The main button to switch to the chat
610
+ chat_button = gr.Button(scale=2)
611
+
612
+ # The delete button for the chat
613
+ delete_button = gr.Button("🗑", scale=0, elem_classes=["tab-button-control"])
614
+
615
+ sidebar_chat_rows.append({
616
+ "row": row,
617
+ "chat_id_state": chat_id_state,
618
+ "chat_button": chat_button,
619
+ "delete_button": delete_button
620
+ })
621
+
622
+ def update_sidebar_display(sidebar_summaries, all_tabs_data, active_uuid):
623
+ updates = []
624
+
625
+ # Use reversed to show the newest chats on top
626
+ chat_uuids_to_display = list(reversed(list(all_tabs_data.keys())))
627
+
628
+ for i in range(MAX_CHATS_IN_SIDEBAR):
629
+ if i < len(chat_uuids_to_display):
630
+ # If we have a chat for this slot, we make the row visible and update it.
631
+ chat_uuid = chat_uuids_to_display[i]
632
+ chat_name = sidebar_summaries.get(chat_uuid, f"Chat {i+1}")
633
+
634
+ elem_classes = ["chat-tab", "active"] if chat_uuid == active_uuid else ["chat-tab"]
635
+
636
+ updates.extend([
637
+ gr.update(visible=True), # Show the row
638
+ chat_uuid, # Set the UUID for this row
639
+ gr.update(value=chat_name, elem_classes=elem_classes), # Update the button text/style
640
+ gr.update(visible=True) # Show the delete button
641
+ ])
642
+ else:
643
+ # If there's no chat for this slot, we hide the entire row.
644
+ updates.extend([
645
+ gr.update(visible=False), # Hide the row
646
+ None, # Clear the state
647
+ gr.update(value=""), # Clear button text
648
+ gr.update(visible=False) # Hide delete button
649
+ ])
650
+ return updates
651
 
652
  chat_interface = gr.ChatInterface(
653
  chatbot=chatbot,
 
663
  current_langgraph_state,
664
  end_of_assistant_response_state
665
  ],
 
666
  multimodal=multimodal,
667
  textbox=textbox,
668
  )
669
 
670
+ # --- Define all event listeners ONCE, outside of any update function ---
671
+ for components in sidebar_chat_rows:
672
+ # Event listener for switching to a different chat
673
+ components["chat_button"].click(
674
+ fn=switch_tab,
675
+ inputs=[
676
+ components["chat_id_state"], # The UUID of the clicked tab
677
+ offloaded_tabs_data_storage,
678
+ current_langgraph_state,
679
+ current_uuid_state,
680
+ chatbot,
681
+ prompt_textbox
682
+ ],
683
+ outputs=[
684
+ current_langgraph_state,
685
+ current_uuid_state,
686
+ chat_interface.chatbot,
687
+ offloaded_tabs_data_storage,
688
+ prompt_textbox,
689
+ *followup_question_buttons,
690
+ ]
691
+ )
692
+
693
+ # Event listener for deleting a chat
694
+ components["delete_button"].click(
695
+ fn=delete_tab,
696
+ inputs=[
697
+ current_uuid_state,
698
+ components["chat_id_state"], # The UUID of the tab to delete
699
+ sidebar_names_state,
700
+ offloaded_tabs_data_storage
701
+ ],
702
+ outputs=[
703
+ sidebar_names_state,
704
+ offloaded_tabs_data_storage,
705
+ chat_interface.chatbot
706
+ ]
707
+ )
708
+
709
+ # --- This section replaces the @gr.render decorator ---
710
+ # We trigger the update function whenever the underlying data changes.
711
+ sidebar_update_triggers = [
712
+ sidebar_names_state,
713
+ offloaded_tabs_data_storage,
714
+ current_uuid_state,
715
+ ]
716
+
717
+ # The list of all components we need to update
718
+ sidebar_update_outputs = []
719
+ for comp_dict in sidebar_chat_rows:
720
+ sidebar_update_outputs.extend(comp_dict.values())
721
+
722
+ for trigger in sidebar_update_triggers:
723
+ trigger.change(
724
+ fn=update_sidebar_display,
725
+ inputs=[sidebar_names_state, offloaded_tabs_data_storage, current_uuid_state],
726
+ outputs=sidebar_update_outputs,
727
+ show_progress="hidden"
728
+ )
729
+
730
+ # Also trigger an update when the app loads
731
+ demo.load(
732
+ fn=update_sidebar_display,
733
+ inputs=[sidebar_names_state, offloaded_tabs_data_storage, current_uuid_state],
734
+ outputs=sidebar_update_outputs,
735
+ show_progress="hidden"
736
+ )
737
+
738
+
739
+ # with gr.Sidebar() as sidebar:
740
+ # @gr.render(inputs=[tab_edit_uuid_state, end_of_assistant_response_state, sidebar_names_state, current_uuid_state, chatbot, offloaded_tabs_data_storage])
741
+ # def render_chats(tab_uuid_edit, end_of_chat_response, sidebar_summaries, active_uuid, messages, tabs):
742
+ # current_tab_button_text = ""
743
+ # if active_uuid not in sidebar_summaries:
744
+ # current_tab_button_text = "Current Chat"
745
+ # elif active_uuid not in tabs:
746
+ # current_tab_button_text = sidebar_summaries[active_uuid]
747
+ # if current_tab_button_text:
748
+ # unique_id = f"current-tab-{active_uuid}-{uuid4()}"
749
+ # gr.Button(
750
+ # current_tab_button_text,
751
+ # elem_classes=["chat-tab", "active"],
752
+ # elem_id=unique_id # Add unique elem_id
753
+ # )
754
+ # for chat_uuid, tab in reversed(tabs.items()):
755
+ # elem_classes = ["chat-tab"]
756
+ # if chat_uuid == active_uuid:
757
+ # elem_classes.append("active")
758
+ # button_uuid_state = gr.State(chat_uuid)
759
+ # with gr.Row():
760
+ # clear_tab_button = gr.Button(
761
+ # "🗑",
762
+ # scale=0,
763
+ # elem_classes=["tab-button-control"],
764
+ # elem_id=f"delete-btn-{chat_uuid}-{uuid4()}" # Add unique ID
765
+ # )
766
+ # clear_tab_button.click(
767
+ # fn=delete_tab,
768
+ # inputs=[
769
+ # current_uuid_state,
770
+ # button_uuid_state,
771
+ # sidebar_names_state,
772
+ # offloaded_tabs_data_storage
773
+ # ],
774
+ # outputs=[
775
+ # sidebar_names_state,
776
+ # offloaded_tabs_data_storage,
777
+ # chat_interface.chatbot_value
778
+ # ]
779
+ # )
780
+ # chat_button_text = sidebar_summaries.get(chat_uuid)
781
+ # if not chat_button_text:
782
+ # chat_button_text = str(chat_uuid)
783
+ # if chat_uuid != tab_uuid_edit:
784
+ # set_edit_tab_button = gr.Button(
785
+ # "✎",
786
+ # scale=0,
787
+ # elem_classes=["tab-button-control"],
788
+ # elem_id=f"edit-btn-{chat_uuid}-{uuid4()}" # Add unique ID
789
+ # )
790
+ # set_edit_tab_button.click(
791
+ # fn=lambda x: x,
792
+ # inputs=[button_uuid_state],
793
+ # outputs=[tab_edit_uuid_state]
794
+ # )
795
+ # chat_tab_button = gr.Button(
796
+ # chat_button_text,
797
+ # elem_id=f"chat-{chat_uuid}-{uuid4()}", # Add truly unique ID
798
+ # elem_classes=elem_classes,
799
+ # scale=2
800
+ # )
801
+ # chat_tab_button.click(
802
+ # fn=switch_tab,
803
+ # inputs=[
804
+ # button_uuid_state,
805
+ # offloaded_tabs_data_storage,
806
+ # current_langgraph_state,
807
+ # current_uuid_state,
808
+ # chatbot,
809
+ # prompt_textbox
810
+ # ],
811
+ # outputs=[
812
+ # current_langgraph_state,
813
+ # current_uuid_state,
814
+ # chat_interface.chatbot_value,
815
+ # offloaded_tabs_data_storage,
816
+ # prompt_textbox,
817
+ # *followup_question_buttons
818
+ # ]
819
+ # )
820
+ # else:
821
+ # chat_tab_text = gr.Textbox(
822
+ # chat_button_text,
823
+ # scale=2,
824
+ # interactive=True,
825
+ # show_label=False,
826
+ # elem_id=f"edit-text-{chat_uuid}-{uuid4()}" # Add unique ID
827
+ # )
828
+ # chat_tab_text.submit(
829
+ # fn=submit_edit_tab,
830
+ # inputs=[
831
+ # button_uuid_state,
832
+ # sidebar_names_state,
833
+ # chat_tab_text
834
+ # ],
835
+ # outputs=[
836
+ # sidebar_names_state,
837
+ # tab_edit_uuid_state
838
+ # ]
839
+ # )
840
+ # # )
841
+ # # return chat_tabs, sidebar_summaries
842
+ # new_chat_button = gr.Button("New Chat", elem_id="new-chat-button")
843
+ # chatbot.clear(fn=clear, outputs=[current_langgraph_state, current_uuid_state])
844
+
845
+ # chat_interface = gr.ChatInterface(
846
+ # chatbot=chatbot,
847
+ # fn=chat_fn,
848
+ # additional_inputs=[
849
+ # current_langgraph_state,
850
+ # current_uuid_state,
851
+ # prompt_textbox,
852
+ # checkbox_search_enabled,
853
+ # checkbox_download_website_text,
854
+ # ],
855
+ # additional_outputs=[
856
+ # current_langgraph_state,
857
+ # end_of_assistant_response_state
858
+ # ],
859
+ # type="messages",
860
+ # multimodal=multimodal,
861
+ # textbox=textbox,
862
+ # )
863
+
864
  new_chat_button.click(
865
  new_tab,
866
  inputs=[
 
990
  return current_prompt
991
 
992
 
993
+ demo.launch(server_name="127.0.0.1", server_port=8080, share=True)
994
 
995
+ # demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
996
 
997
 
998
 
setup.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ create a virtual enviremetn | windows --> python -m venv venv
2
+ activate the virtual environment | ./venv/scripts/activate
3
+ instll the requirements | pip install -r requirements.txt
4
+ run the project | gradio app.py
5
+
6
+ **make sure environment variable are set correctly**