import random import gradio as gr def random_choice(choice_type, options, output): if choice_type == "Yes/No": choices = ["Yes", "No"] else: choices = [option.strip() for option in options.split(",")] random_choice = random.choice(choices) output = gr.update(visible=True, value=random_choice) return output with gr.Blocks() as demo: gr.Markdown("# QuikChoice") gr.Markdown("Random Choice Generator by **[Naman Pandey](https://nmn-pandey.github.io)**") gr.Markdown("Whether you're seeking a quick \"Yes/No\" answer or decide which movie to watch, let this app generate random choices from your options, making it easier to move forward without the stress of indecision.") with gr.Row(): choice_type = gr.Radio(["Yes/No", "Custom Options"], label="Choice Type") options_input = gr.Textbox(label="Enter options (comma-separated)", visible=False) # gr.Markdown("## OR") show_choice_btn = gr.Button("Make a Choice") output = gr.Textbox(label="Random Choice", visible=False) choice_type.change( fn=lambda choice_type: gr.update(visible = (choice_type == "Custom Options")), inputs=choice_type, outputs=options_input ) # @show_choice_btn.click(inputs=options_input,outputs=output) show_choice_btn.click( fn=random_choice, inputs=[choice_type, options_input, output], outputs=output ) demo.launch(share=True)