add model change button
Browse files23 unmodified lines24252627282930 unmodified lines60616263646566108 unmodified lines1751761771781791808 unmodified lines18919019119219319410 unmodified lines2052062072082092108 unmodified lines21922022122222322432 unmodified lines2572582592602612626 unmodified lines26927027127227327427527627711 unmodified lines28929029129229329429532 unmodified lines3283293303313323333345 unmodified lines34034134234334434534634734834935023 unmodified linesAlways output only the HTML code inside a ```html ... ``` code block, and do not include any explanations or extra text."""DEMO_LIST = [{"title": "Todo App",30 unmodified lines]# HF Inference ClientYOUR_API_TOKEN = os.getenv('HF_TOKEN3')client = InferenceClient(provider="auto",api_key=YOUR_API_TOKEN,108 unmodified linessetting = gr.State({"system": SystemPrompt,})with ms.Application() as app:with antd.ConfigProvider():8 unmodified lines<h1>Hugging Face Coder</h1></div>""")input = antd.InputTextarea(size="large", allow_clear=True, placeholder="Please enter what kind of application you want", visible=False)btn = antd.Button("send", type="primary", size="large", visible=False)10 unmodified lineswith antd.Flex(gap="small", wrap=True, visible=False) as setting_flex:settingPromptBtn = antd.Button("βοΈ set system Prompt", type="default", visible=False)codeBtn = antd.Button("π§βπ» view code", type="default", visible=False)historyBtn = antd.Button("π history", type="default", visible=False)8 unmodified linessystem_prompt_modal.cancel(lambda: gr.update(open=False), outputs=[system_prompt_modal])with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:code_output = legacy.Markdown()32 unmodified linesgr.update(visible=False),gr.update(visible=False),gr.update(visible=False),)else:return (6 unmodified linesgr.update(visible=True),gr.update(visible=True),gr.update(visible=True),)def generation_code(query: Optional[str], _setting: Dict[str, str], _history: Optional[History], profile: gr.OAuthProfile | None):if profile is None:return ("Please sign in with Hugging Face to use this feature.",11 unmodified linestry:completion = client.chat.completions.create(model="deepseek-ai/DeepSeek-V3-0324",messages=messages,stream=True)32 unmodified linesbtn.click(generation_code,inputs=[input, setting, history],outputs=[code_output, history, sandbox, state_tab, code_drawer])5 unmodified linesoutputs=[login_message,input,btn,clear_btn,examples_flex,setting_flex,settingPromptBtn,codeBtn,historyBtn,]23 unmodified lines242526272829303132333435363738394041424330 unmodified lines74757677787980108 unmodified lines1891901911921931941958 unmodified lines20420520620720820921010 unmodified lines2212222232242252262278 unmodified lines23623723823924024124224324424524624724824925032 unmodified lines2832842852862872882892906 unmodified lines29729829930030130230330430530630711 unmodified lines31932032132232332432532 unmodified lines3583593603613623633645 unmodified lines37037137237337437537637737837938038138223 unmodified linesAlways output only the HTML code inside a ```html ... ``` code block, and do not include any explanations or extra text."""# Available modelsAVAILABLE_MODELS = [{"name": "DeepSeek V3","id": "deepseek-ai/DeepSeek-V3-0324","description": "DeepSeek V3 model for code generation"},{"name": "DeepSeek R1","id": "deepseek-ai/DeepSeek-R1-0528","description": "DeepSeek R1 model for code generation"}]DEMO_LIST = [{"title": "Todo App",30 unmodified lines]# HF Inference ClientYOUR_API_TOKEN = os.getenv('HF_TOKEN')client = InferenceClient(provider="auto",api_key=YOUR_API_TOKEN,108 unmodified linessetting = gr.State({"system": SystemPrompt,})current_model = gr.State(AVAILABLE_MODELS[0]) # Default to first modelwith ms.Application() as app:with antd.ConfigProvider():8 unmodified lines<h1>Hugging Face Coder</h1></div>""")current_model_display = gr.Markdown("**Current Model:** DeepSeek V3", visible=False)input = antd.InputTextarea(size="large", allow_clear=True, placeholder="Please enter what kind of application you want", visible=False)btn = antd.Button("send", type="primary", size="large", visible=False)10 unmodified lineswith antd.Flex(gap="small", wrap=True, visible=False) as setting_flex:settingPromptBtn = antd.Button("βοΈ set system Prompt", type="default", visible=False)modelBtn = antd.Button("π€ switch model", type="default", visible=False)codeBtn = antd.Button("π§βπ» view code", type="default", visible=False)historyBtn = antd.Button("π history", type="default", visible=False)8 unmodified linessystem_prompt_modal.cancel(lambda: gr.update(open=False), outputs=[system_prompt_modal])with antd.Modal(open=False, title="Select Model", width="600px") as model_modal:with antd.Flex(vertical=True, gap="middle"):for i, model in enumerate(AVAILABLE_MODELS):with antd.Card(hoverable=True, title=model["name"]) as modelCard:antd.CardMeta(description=model["description"])modelCard.click(lambda m=model: (m, gr.update(open=False), f"**Current Model:** {m['name']}"), outputs=[current_model, model_modal, current_model_display])modelBtn.click(lambda: gr.update(open=True), inputs=[], outputs=[model_modal])with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:code_output = legacy.Markdown()32 unmodified linesgr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),gr.update(visible=False),)else:return (6 unmodified linesgr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),gr.update(visible=True),)def generation_code(query: Optional[str], _setting: Dict[str, str], _history: Optional[History], profile: gr.OAuthProfile | None, _current_model: Dict):if profile is None:return ("Please sign in with Hugging Face to use this feature.",11 unmodified linestry:completion = client.chat.completions.create(model=_current_model["id"],messages=messages,stream=True)32 unmodified linesbtn.click(generation_code,inputs=[input, setting, history, current_model],outputs=[code_output, history, sandbox, state_tab, code_drawer])5 unmodified linesoutputs=[login_message,input,current_model_display,btn,clear_btn,examples_flex,setting_flex,settingPromptBtn,modelBtn,codeBtn,historyBtn,]
app.py+36-4