add model change button
Browse files23 unmodified lines242526272829303132333435363738394041424330 unmodified lines7475766377787980108 unmodified lines1891901911921931941958 unmodified lines20420520620720820921010 unmodified lines2212222232242252262278 unmodified lines23623723823924024124224324424524624724824925032 unmodified lines2832842852862872882892906 unmodified lines29729829930030130230327430430530630711 unmodified lines31932032129232232332432532 unmodified lines3583593603313613623633645 unmodified lines37037137237337437537637737837938038138223 unmodified lines
Always 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_TOKEN3')YOUR_API_TOKEN = os.getenv('HF_TOKEN')client = InferenceClient( provider="auto", api_key=YOUR_API_TOKEN,108 unmodified lines setting = gr.State({ "system": SystemPrompt, }) current_model = gr.State(AVAILABLE_MODELS[0]) # Default to first model
with 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 lines with 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 lines system_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 lines gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), ) else: return (6 unmodified lines gr.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): 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 lines
try: completion = client.chat.completions.create( model="deepseek-ai/DeepSeek-V3-0324", model=_current_model["id"], messages=messages, stream=True )32 unmodified lines
btn.click( generation_code, inputs=[input, setting, history], inputs=[input, setting, history, current_model], outputs=[code_output, history, sandbox, state_tab, code_drawer] ) 5 unmodified lines outputs=[ login_message, input, current_model_display, btn, clear_btn, examples_flex, setting_flex, settingPromptBtn, modelBtn, codeBtn, historyBtn, ]app.py+36-4