@@ -85,6 +85,7 @@ def chat_fn(
8585 config : Optional [Dict ],
8686 messages : Optional [List [Dict ]],
8787 agent : NeurIPS2025Agent ,
88+ width : int ,
8889) -> Tuple [List [Dict ], Optional [List [Dict ]]]:
8990 """
9091 Handle chat interaction using stateless agent.
@@ -120,6 +121,10 @@ def chat_fn(
120121 history .extend ([user_msg_dict , assistant_msg_dict ])
121122
122123 try :
124+ if width < 1200 :
125+ LOGGER .info ("Detected small screen width, appending note to user message." )
126+ new_message += "\n \n (Note: You are using a small screen device. Please format your responses accordingly to ensure readability. Please never use tables.)"
127+
123128 # Create user message with timestamp
124129 user_message = {
125130 "role" : "user" ,
@@ -129,6 +134,8 @@ def chat_fn(
129134
130135 # Add user message to conversation
131136 messages .append (user_message )
137+ history [- 1 ]["content" ] = "Working on it. Hang tight..."
138+ yield history , messages
132139
133140 # Stream the response
134141 accumulated_response = ""
@@ -287,9 +294,9 @@ def clear_chat(
287294 return [], reset_messages
288295
289296
290- def submit_message (message , history , config , messages , agent ):
297+ def submit_message (message , history , config , messages , agent , width ):
291298 """Wrapper to clear input and process message"""
292- yield from chat_fn (message , history , config , messages , agent )
299+ yield from chat_fn (message , history , config , messages , agent , width )
293300
294301
295302def main ():
@@ -306,7 +313,7 @@ def main():
306313 primary_hue = gr .themes .colors .slate ,
307314 secondary_hue = gr .themes .colors .blue
308315 ),
309- css = """
316+ css = """
310317 #submit_textbox button {
311318 background-color: #ff6b6b !important;
312319 border-color: #ff6b6b !important;
@@ -333,9 +340,9 @@ def main():
333340 with gr .Row ():
334341 with gr .Column ():
335342 gr .Markdown ("""
336- <sub><sup> **Note:** This is an experimental deployment and LLMs can make mistakes. This can mean that the agent may not
343+ **Note:** This is an experimental deployment and LLMs can make mistakes. This can mean that the agent may not
337344 discover your paper even though it is presented at the conference. Also, note that the ordering of authors may
338- not be correct. Check the paper links for more details.<sub><sup>
345+ not be correct. Check the paper links for more details.
339346 """ )
340347
341348 # Main chat interface
@@ -363,6 +370,13 @@ def main():
363370 )
364371 # submit_btn = gr.Button("Send", variant="primary", scale=1)
365372
373+ # Hidden width input – value set from JS on submit
374+ width_box = gr .Number (
375+ visible = False ,
376+ elem_id = "width_box" ,
377+ )
378+
379+
366380 with gr .Row ():
367381 clear_btn = gr .Button ("🗑️ Clear Chat" , size = "sm" )
368382 # save_btn = gr.Button("💾 Save History", size="sm")
@@ -510,10 +524,24 @@ def main():
510524 outputs = [config_state , init_status ]
511525 )
512526
527+ def streaming_submit (msg_input , chatbot , config_state , messages_state , width ):
528+ # Immediately clear the input (first yield)
529+ yield chatbot , messages_state , ""
530+
531+ # Then stream the real results
532+ for new_chatbot , new_messages_state in submit_message (msg_input , chatbot , config_state , messages_state , agent , width ):
533+ yield new_chatbot , new_messages_state , ""
534+
535+
513536 msg_input .submit (
514- fn = lambda msg_input , chatbot , config_state , messages_state : (yield from submit_message (msg_input , chatbot , config_state , messages_state , agent )),
515- inputs = [msg_input , chatbot , config_state , messages_state ],
516- outputs = [chatbot , messages_state ]
537+ fn = streaming_submit , # lambda msg_input, chatbot, config_state, messages_state: (yield from submit_message(msg_input, chatbot, config_state, messages_state, agent)),
538+ inputs = [msg_input , chatbot , config_state , messages_state , width_box ],
539+ outputs = [chatbot , messages_state , msg_input ],
540+ js = """
541+ (msg_input, chatbot, config_state, messages_state, width_box) => {
542+ return [msg_input, chatbot, config_state, messages_state, window.innerWidth];
543+ }
544+ """ ,
517545 ).then (
518546 fn = lambda : "" ,
519547 inputs = None ,
0 commit comments