DEMO 2-1: Interactive Multi-Component Gradio Interface

import gradio as gr

# Define the process function
def process_inputs(text_input, number_input, number_slider, dropdown_selection, radio_options, image_input):
    
    processed_text = f"You entered: {text_input}" 
    processed_number = f"You entered: {number_input}" 
    processed_slider = f"Number selected from slider: {number_slider}" 
    processed_dropdown = f"You selected from dropdown: {dropdown_selection}" 
    processed_radio = f"You selected from radio buttons: {radio_options}" 
    
    if image_input is not None:
        imageshape = f"The shape of the selected image is: {image_input.shape}"
        return processed_text, processed_number, processed_slider, processed_dropdown, processed_radio, imageshape
    else:
        return processed_text, processed_number, processed_slider, processed_dropdown, processed_radio, None

# Create a complex interface 
demo = gr.Interface(
    fn=process_inputs,  # The process function
    inputs=[
        gr.Textbox(label="Text Input"),  # Textbox for text input
        gr.Number(minimum=5, maximum=100, step=10, label="Number"),  # Number input with a range
        gr.Slider(minimum=0, maximum=100, step=1, label="Number Slider"),  # Slider for number selection
        gr.Dropdown(choices=["Option 1", "Option 2", "Option 3"], label="Dropdown Selection"),  # Dropdown for selection
        gr.Radio(choices=["Radio 1", "Radio 2", "Radio 3"], label="Radio Options"),  # Radio buttons for selection
        gr.Image(label="Upload Image", type="numpy"),  # Image upload component
    ],
    outputs=[
        gr.Text(label="Processed Text"), 
        gr.Text(label="Processed Number"), 
        gr.Text(label="Processed Slider"), 
        gr.Text(label="Processed Dropdown"),  
        gr.Text(label="Processed Radio"),  
        gr.Text(label="Processed Image")  
    ],
    title="Complex Gradio Interface with Multiple Components",  # Title of the app
    description="This interface demonstrates the use of various input components such as textbox, slider, dropdown, radio, and image upload."  # Description of the interface
)

demo.launch(debug=True)