Spaces:
Build error
Build error
initial upload
Browse files- app.py +61 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas
|
| 3 |
+
import PIL
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Dummy function for Workflow A
|
| 8 |
+
def workflow_a(image, text):
|
| 9 |
+
# Here you might process the image/text in a specific way.
|
| 10 |
+
return "Workflow A executed!"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Dummy function for Workflow B
|
| 14 |
+
def workflow_b(image, text):
|
| 15 |
+
# Here you might process the image/text in a different way.
|
| 16 |
+
return "Workflow B executed!"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Main function triggered by the Start button.
|
| 20 |
+
# It uses an if statement to decide which workflow to call.
|
| 21 |
+
def main(image, text):
|
| 22 |
+
# Example condition: if the text (after stripping whitespace) equals "a" (case-insensitive), call workflow_a.
|
| 23 |
+
if text.strip().lower() == "a":
|
| 24 |
+
result_text = workflow_a(image, text)
|
| 25 |
+
else:
|
| 26 |
+
result_text = workflow_b(image, text)
|
| 27 |
+
|
| 28 |
+
# Forward the input image to both image outputs.
|
| 29 |
+
return image, image, result_text
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Build the Gradio interface using Blocks for a custom layout.
|
| 34 |
+
with gr.Blocks() as demo:
|
| 35 |
+
gr.Markdown("## Gradio Demo: Workflow Selector")
|
| 36 |
+
|
| 37 |
+
# Input components in a row.
|
| 38 |
+
with gr.Row():
|
| 39 |
+
image_input = gr.Image(label="Input Image")
|
| 40 |
+
text_input = gr.Textbox(label="Input Text", placeholder='Type "a" for workflow A or anything else for workflow B')
|
| 41 |
+
|
| 42 |
+
# Start button to trigger the main function.
|
| 43 |
+
start_button = gr.Button("Start")
|
| 44 |
+
|
| 45 |
+
gr.Markdown("### Outputs")
|
| 46 |
+
# Output images in a row.
|
| 47 |
+
with gr.Row():
|
| 48 |
+
output_image1 = gr.Image(label="Output Image 1")
|
| 49 |
+
output_image2 = gr.Image(label="Output Image 2")
|
| 50 |
+
|
| 51 |
+
output_text = gr.Textbox(label="Output Text")
|
| 52 |
+
|
| 53 |
+
# Connect the Start button to the main function.
|
| 54 |
+
start_button.click(
|
| 55 |
+
fn=main,
|
| 56 |
+
inputs=[image_input, text_input],
|
| 57 |
+
outputs=[output_image1, output_image2, output_text]
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Launch the Gradio app.
|
| 61 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
PIL
|