File size: 2,179 Bytes
fe2316a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ed001f
fe2316a
 
 
 
 
 
 
 
 
acc4968
8ed001f
 
 
f0de930
fe2316a
 
 
 
 
 
 
5cc0c8f
fe2316a
 
 
 
 
 
 
5cc0c8f
 
 
fe2316a
 
f0de930
fe2316a
 
 
 
8ed001f
 
 
f0de930
fe2316a
 
 
 
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
59
60
61
62
63
64
65
66
67
68
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_ori(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, result_text

def main(text):
    # Example condition: if the text (after stripping whitespace) equals "a" (case-insensitive), call workflow_a.
    
    # Forward the input image to both image outputs.
    return "ok, that worked!", "another text output"

# 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")
    output_text_b = gr.Textbox(label="Output Text B")

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

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