File size: 1,464 Bytes
0bbed06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)