File size: 1,787 Bytes
ba78e5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import pandas
import PIL


# Dummy function for Workflow A
def workflow_a(image, text):
    # Here you might process the image/text in a specific way.
    return "Workflow A executed!"


# Dummy function for Workflow B
def workflow_b(image, text):
    # Here you might process the image/text in a different way.
    return "Workflow B executed!"

# Main function triggered by the Start button.
# It uses an if statement to decide which workflow to call.
def main(image, text):
    # Example condition: if the text (after stripping whitespace) equals "a" (case-insensitive), call workflow_a.
    if text.strip().lower() == "a":
        result_text = workflow_a(image, text)
    else:
        result_text = workflow_b(image, text)

    # Forward the input image to both image outputs.
    return image, image, 


# Build the Gradio interface using Blocks for a custom layout.
with gr.Blocks() as demo:
    gr.Markdown("## Gradio Demo: Workflow Selector")

    # Input components in a row.
    with gr.Row():
        image_input = gr.Image(label="Input Image")
        text_input = gr.Textbox(label="Input Text", placeholder='Type "a" for workflow A or anything else for workflow B')

    # Start button to trigger the main function.
    start_button = gr.Button("Start")

    gr.Markdown("### Outputs")
    # Output images in a row.
    with gr.Row():
        output_image1 = gr.Image(label="Output Image 1")
        output_image2 = gr.Image(label="Output Image 2")

    output_text = gr.Textbox(label="Output Text")

    # Connect the Start button to the main function.
    start_button.click(
        fn=main,
        inputs=[image_input, text_input],
        outputs=[output_image1, output_image2, output_text]
    )

# Launch the Gradio app.
demo.launch(share=True)