Update app.py
Browse files7 unmodified lines891011121313 unmodified lines272829303132333435363738394041424317 unmodified lines6162636465666768697071727374757677787980818283848586877 unmodified linesdef respond(message,history: list[tuple[str, str]],system_message,13 unmodified linesresponse = ""for message in client.chat_completion(messages,max_tokens=max_tokens,stream=True,temperature=temperature,top_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response# CSS for styling the interface17 unmodified lines}"""# Function to trigger different AI models based on button clickdef trigger_model(model_name, message, history, system_message, max_tokens, temperature, top_p):if model_name == "Llama":# Here, you can choose the llama model to generate a responsereturn respond(message, history, system_message, max_tokens, temperature, top_p)elif model_name == "Chatgpt":# Placeholder for ChatGPT function (if needed)return "ChatGPT response goes here."elif model_name == "Claude":# Placeholder for Claude function (if needed)return "Claude response goes here."else:return "Model not found."# Define the Gradio interfacedemo = gr.Interface(fn=trigger_model,inputs=[gr.Textbox(value="Hello!", label="User Message"),gr.Textbox(value="System message", label="System Message", visible=False),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(7 unmodified lines89101112131413 unmodified lines2829303132333435363738394041424344454647484950515217 unmodified lines707172737475767778798081828384857 unmodified linesdef respond(model_name,message,history: list[tuple[str, str]],system_message,13 unmodified linesresponse = ""# Model selection based on the button clickif model_name == "Llama":for message in client.chat_completion(messages,max_tokens=max_tokens,stream=True,temperature=temperature,top_p=top_p,):token = message.choices[0].delta.contentresponse += tokenelif model_name == "Chatgpt":response = "ChatGPT functionality is not yet implemented."elif model_name == "Claude":response = "Claude functionality is not yet implemented."else:response = "Model not recognized."return response# CSS for styling the interface17 unmodified lines}"""# Define the Gradio interface with buttons and model selectiondef gradio_interface(model_name, message, history, system_message, max_tokens, temperature, top_p):return respond(model_name, message, history, system_message, max_tokens, temperature, top_p)demo = gr.Interface(fn=gradio_interface,inputs=[gr.Textbox(value="Hello!", label="User Message"),gr.Textbox(value="You are a virtual health assistant. Your primary goal is to assist with health-related queries.", label="System Message", visible=False),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(
app.py+24-26