gr.ChatInterface(get_most_similar_question,chatbot=chatbot,title=title,theme=gr.themes.Base(),examples=["Hi", "What is the sales for yesterday", "What is the sales for each region for GT channel yesterday","What is competitor wise market share for month may and year 2024","show me SAMSUNG market share for month may and year 2024","top 5 performing competitors by sellout value under GT/MT channel for month may and year 2024","show me Samsung market share for above 40 k priceband for month may and year 2024"],css="footer{display:none !important}",autofocus=True).queue().launch(auth=authenticate_user, share=True,show_error=False,server_name= '0.0.0.0', server_port=7898)
add threee radio buttons at the top with these
Assistant
To add three radio buttons at the top of your Gradio interface, you can use the gradio.Layout API to combine the radio buttons with your chatbot interface. Below is an example showing how you can modify your existing code to integrate three radio buttons at the top.
python
import gradio as gr
# Define the options for the radio buttons
radio_options = ["Option 1", "Option 2", "Option 3"]
# Function to handle the radio button change
def on_radio_change(selection):
print(f"Selected radio button: {selection}")
# Handle the change in selection here as needed
# Create the radio buttons
radio_buttons = gr.Radio(label="Select an option", choices=radio_options, value=radio_options[0], interactive=True, elem_id="radio_buttons")
# Function that powers your chatbot
def get_most_similar_question(input_text):
# Your function logic here
return "Response based on the most similar question."
# Title of the Chat Interface
title = "Your Chatbot Title"
# Create the Chatbot interface with specified properties
chatbot = gr.Chatbot(show_copy_button=True, likeable=True, sanitize_html=True)
# Define the ChatInterface with the radio buttons on top
interface = gr.ChatInterface(
fn=get_most_similar_question,
chatbot=chatbot,
title=title,
theme=gr.themes.Base(),
examples=["Hi", "What is the sales for yesterday", "What is the sales for each region for GT channel yesterday",
"What is competitor wise market share for month may and year 2024",
"show me SAMSUNG market share for month may and year 2024",
"top 5 performing competitors by sellout value under GT/MT channel for month may and year 2024",
"show me Samsung market share for above 40 k priceband for month may and year 2024"],
css="footer{display:none !important}",
autofocus=True
)
# Integrate the radio buttons and the ChatInterface
with gr.Blocks() as demo:
gr.Row([radio_buttons])
interface.queue()
# Add event listener for radio button change
radio_buttons.change(on_radio_change, inputs=radio_buttons)
# Launch the interface with authentication, sharing options, and server parameters
demo.launch(auth=authenticate_user, share=True, show_error=False, server_name='0.0.0.0', server_port=7898)
Here's a summary of the updates made:
Created a radio_buttons element with the predefined options.
Defined a function on_radio_change to handle changes in radio button selection.
Used the gr.Blocks() context to combine the radio buttons and the gr.ChatInterface.
Listened to changes in radio button selections using the radio_buttons.change() method.
This code will add the radio buttons at the top of your chat interface and handle selection changes accordingly.