show defaults
Browse files88 unmodified lines89909192939495961680 unmodified lines17771778177917801781177817821783178417858 unmodified lines17941795179617971798179317991800180118023 unmodified lines1806180718081803180918101811181218131814181518161817181818191820182118221823182418252 unmodified lines1828182918301813183118321833183412 unmodified lines184718481849183218501851185218531854183718551856185718581 unmodified line18601861186218451863186418651866186718501868186918701871187218731874187518761877187818791880188118821883188418853 unmodified lines1889189018911861189218931894189518 unmodified lines191419151916188619171918191919201921189119221923192419252 unmodified lines1928192919301900193119321933193488 unmodified lines current_model = gr.State(DEFAULT_MODEL) open_panel = gr.State(None) last_login_state = gr.State(None) models_first_change = gr.State(True) spaces_first_change = gr.State(True)
with gr.Sidebar() as sidebar: login_button = gr.LoginButton()1680 unmodified lines models = get_trending_models(limit=10) # Create choices list with display names and values as model IDs choices = [(display, model_id) for display, model_id in models] # Set first model as default value if available default_value = models[0][1] if models and len(models) > 0 and models[0][1] != "" else None return gr.update(choices=choices) return gr.update(choices=choices, value=default_value) demo.load( load_trending_models,8 unmodified lines spaces = get_trending_spaces(limit=10) # Create choices list with display names and values as space IDs choices = [(display, space_id) for display, space_id in spaces] # Set first space as default value if available default_value = spaces[0][1] if spaces and len(spaces) > 0 and spaces[0][1] != "" else None return gr.update(choices=choices) return gr.update(choices=choices, value=default_value) demo.load( load_trending_spaces,3 unmodified lines ) # Handle trending model selection def handle_trending_model_selection(model_id, hist): def handle_trending_model_selection(model_id, hist, is_first): """Handle when user selects a trending model""" # Skip import on first change (when default value is set on load) if is_first: return [ gr.update(), # status gr.update(), # code_output gr.update(), # language_dropdown hist, # history history_to_chatbot_messages(hist), # history_output history_to_chatbot_messages(hist), # chat_history False # Set first_change to False after first trigger ] if not model_id or model_id == "": return [ gr.update(value="Please select a model.", visible=True), # status2 unmodified lines hist, # history history_to_chatbot_messages(hist), # history_output history_to_chatbot_messages(hist), # chat_history gr.update(value=None) # reset dropdown False # Keep first_change as False ] # Import the model12 unmodified lines loaded_history, # history history_to_chatbot_messages(loaded_history), # history_output history_to_chatbot_messages(loaded_history), # chat_history gr.update(value=None) # reset dropdown False # Keep first_change as False ] trending_models_dropdown.change( handle_trending_model_selection, inputs=[trending_models_dropdown, history], inputs=[trending_models_dropdown, history, models_first_change], outputs=[ trending_models_status, code_output,1 unmodified line history, history_output, chat_history, trending_models_dropdown models_first_change ] ) # Handle trending space selection def handle_trending_space_selection(space_id, hist): def handle_trending_space_selection(space_id, hist, is_first): """Handle when user selects a trending space""" # Skip import on first change (when default value is set on load) if is_first: return [ gr.update(), # status gr.update(), # code_output gr.update(), # language_dropdown hist, # history history_to_chatbot_messages(hist), # history_output history_to_chatbot_messages(hist), # chat_history gr.update(), # deploy_btn False # Set first_change to False after first trigger ] if not space_id or space_id == "": return [ gr.update(value="Please select a space.", visible=True), # status3 unmodified lines history_to_chatbot_messages(hist), # history_output history_to_chatbot_messages(hist), # chat_history gr.update(visible=True), # deploy_btn gr.update(value=None) # reset dropdown False # Keep first_change as False ] # Import the space18 unmodified lines history_to_chatbot_messages(loaded_history), # history_output history_to_chatbot_messages(loaded_history), # chat_history gr.update(value="Publish", visible=True), # deploy_btn gr.update(value=None) # reset dropdown False # Keep first_change as False ] trending_spaces_dropdown.change( handle_trending_space_selection, inputs=[trending_spaces_dropdown, history], inputs=[trending_spaces_dropdown, history, spaces_first_change], outputs=[ trending_spaces_status, code_output,2 unmodified lines history_output, chat_history, deploy_btn, trending_spaces_dropdown spaces_first_change ] )
anycoder_app/ui.py+43-12