2222from kotaemon .base import Document
2323from kotaemon .indices .ingests .files import KH_DEFAULT_FILE_EXTRACTORS
2424
25- from ...utils import SUPPORTED_LANGUAGE_MAP , get_file_names_regex
25+ from ...utils import SUPPORTED_LANGUAGE_MAP , get_file_names_regex , get_urls
2626from .chat_panel import ChatPanel
2727from .common import STATE
2828from .control import ConversationControl
@@ -140,6 +140,7 @@ def on_building_ui(self):
140140 # get the file selector choices for the first index
141141 if index_id == 0 :
142142 self .first_selector_choices = index_ui .selector_choices
143+ self .first_indexing_url_fn = None
143144
144145 if gr_index :
145146 if isinstance (gr_index , list ):
@@ -284,6 +285,7 @@ def on_register_events(self):
284285 self .chat_panel .text_input ,
285286 self .chat_panel .chatbot ,
286287 self ._app .user_id ,
288+ self ._app .settings_state ,
287289 self .chat_control .conversation_id ,
288290 self .chat_control .conversation_rn ,
289291 self .first_selector_choices ,
@@ -634,6 +636,7 @@ def submit_msg(
634636 chat_input ,
635637 chat_history ,
636638 user_id ,
639+ settings ,
637640 conv_id ,
638641 conv_name ,
639642 first_selector_choices ,
@@ -643,22 +646,44 @@ def submit_msg(
643646 raise ValueError ("Input is empty" )
644647
645648 chat_input_text = chat_input .get ("text" , "" )
649+ file_ids = []
646650
647- # get all file names with pattern @"filename" in input_str
648- file_names , chat_input_text = get_file_names_regex (chat_input_text )
649651 first_selector_choices_map = {
650652 item [0 ]: item [1 ] for item in first_selector_choices
651653 }
652- file_ids = []
653654
654- if file_names :
655+ # get all file names with pattern @"filename" in input_str
656+ file_names , chat_input_text = get_file_names_regex (chat_input_text )
657+ # get all urls in input_str
658+ urls , chat_input_text = get_urls (chat_input_text )
659+
660+ if urls and self .first_indexing_url_fn :
661+ print ("Detected URLs" , urls )
662+ file_ids = self .first_indexing_url_fn (
663+ "\n " .join (urls ),
664+ True ,
665+ settings ,
666+ user_id ,
667+ )
668+ elif file_names :
655669 for file_name in file_names :
656670 file_id = first_selector_choices_map .get (file_name )
657671 if file_id :
658672 file_ids .append (file_id )
659673
674+ # add new file ids to the first selector choices
675+ first_selector_choices .extend (zip (urls , file_ids ))
676+
677+ # if file_ids is not empty and chat_input_text is empty
678+ # set the input to summary
679+ if not chat_input_text and file_ids :
680+ chat_input_text = "Summary"
681+
660682 if file_ids :
661- selector_output = ["select" , file_ids ]
683+ selector_output = [
684+ "select" ,
685+ gr .update (value = file_ids , choices = first_selector_choices ),
686+ ]
662687 else :
663688 selector_output = [gr .update (), gr .update ()]
664689
0 commit comments