Spaces:
Sleeping
Sleeping
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) |