Update app.py
Browse files7 unmodified lines89101112131413 unmodified lines282930313230313233343536373334353637383940414243444546474839404950515217 unmodified lines70717264656667686970717273747576737475767779788179808184828384857 unmodified lines
def respond( model_name, message, history: list[tuple[str, str]], system_message,13 unmodified lines
response = ""
# Model selection based on the button click if 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.content for message in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p, ): token = message.choices[0].delta.content response += token elif 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."
response += token yield response return 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 response return 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 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)
# Define the Gradio interfacedemo = gr.Interface( fn=trigger_model, fn=gradio_interface, inputs=[ gr.Textbox(value="Hello!", label="User Message"), gr.Textbox(value="System message", label="System Message", visible=False), 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