Update app.py
Browse files48 unmodified lines495051525354555657585960616263646566676869707172737475767778798081828384851 unmodified line878889909192935 unmodified lines9910010110210310410548 unmodified linesresponse += tokenyield response# Adding the model name at the end of the responseyield f"\n\n[Response generated by model: {model_name}]"# Model names and their custom display namesmodel_choices = [("HuggingFaceH4/zephyr-7b-beta", "Lake [Test]"),("google/mt5-base", "Lake 1 Base"),("google/mt5-large", "Lake 1 Advanced")]# Convert model choices into just the model names for the dropdownmodel_names = [model[0] for model in model_choices]# Function to handle model selection and display name for the modeldef respond_with_model_name(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p,model_name):# Find the display name of the selected modelmodel_display_name = dict(model_choices)[model_name]# Call the existing respond functionresponse = list(respond(message, history, system_message, max_tokens, temperature, top_p, model_name))# Add model name at the end of the responseresponse[-1] += f"\n\n[Response generated by: {model_display_name}]"return response1 unmodified lineFor information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond_with_model_name,additional_inputs=[gr.Textbox(value="You are a friendly Chatbot.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),5 unmodified linesstep=0.05,label="Top-p (nucleus sampling)",),gr.Dropdown(model_names, label="Select Model", value=model_names[0]) # Model selection dropdown],)48 unmodified lines495051525354555657585960616263646566676869707172737475767778798081821 unmodified line848586878889905 unmodified lines9697989910010110248 unmodified linesresponse += tokenyield response# Model names and their pseudonymsmodel_choices = [("HuggingFaceH4/zephyr-7b-beta", "Lake [Test]"),("google/mt5-base", "Lake 1 Base"),("google/mt5-large", "Lake 1 Advanced")]# Convert pseudonyms to model names for the dropdownpseudonyms = [model[1] for model in model_choices]# Function to handle model selection and pseudonymsdef respond_with_pseudonym(message,history: list[tuple[str, str]],system_message,max_tokens,temperature,top_p,selected_pseudonym):# Find the actual model name from the pseudonymmodel_name = next(model[0] for model in model_choices if model[1] == selected_pseudonym)# Call the existing respond functionresponse = list(respond(message, history, system_message, max_tokens, temperature, top_p, model_name))# Add pseudonym at the end of the responseresponse[-1] += f"\n\n[Response generated by: {selected_pseudonym}]"return response1 unmodified lineFor information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond_with_pseudonym,additional_inputs=[gr.Textbox(value="You are a friendly Chatbot.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),5 unmodified linesstep=0.05,label="Top-p (nucleus sampling)",),gr.Dropdown(pseudonyms, label="Select Model", value=pseudonyms[0]) # Pseudonym selection dropdown],)
app.py+12-15