Spaces:
Sleeping
Sleeping
File size: 2,367 Bytes
2404210 |
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 69 70 71 72 73 74 |
import gradio as gr
import numpy as np
def process_text(text):
return f"You said: {text}"
def flip_image(image):
return np.fliplr(image)
def process_audio(audio):
return f"Received audio file: {audio[0]}"
def get_selected_option(option):
return f"You selected: {option}"
with gr.Blocks() as demo:
# Markdown Header
gr.Markdown("# Comprehensive Gradio Interface")
# Row and Column Layout for Text Processing
with gr.Row():
with gr.Column():
with gr.Group(): # Group for Text Input
text_input = gr.Textbox(
label="Enter Text", placeholder="Type something..."
)
submit_btn = gr.Button("Submit")
with gr.Column():
text_output = gr.Textbox(label="Output", interactive=False)
# Button click event for text processing
submit_btn.click(fn=process_text, inputs=text_input, outputs=text_output)
# Tab Layout
with gr.Tabs():
with gr.Tab("Image Flipper"):
image_input = gr.Image(type="numpy", label="Upload Image")
image_output = gr.Image(label="Flipped Image")
flip_btn = gr.Button("Flip Image")
flip_btn.click(fn=flip_image, inputs=image_input, outputs=image_output)
with gr.Tab("Audio Processor"):
audio_input = gr.Audio(label="Upload Audio")
audio_output = gr.Textbox(label="Audio Output", interactive=False)
audio_btn = gr.Button("Process Audio")
audio_btn.click(fn=process_audio, inputs=audio_input, outputs=audio_output)
with gr.Tab("Options"):
dropdown = gr.Dropdown(
choices=["Option 1", "Option 2", "Option 3"], label="Choose an Option"
)
option_output = gr.Textbox(label="Selected Option", interactive=False)
dropdown.change(
fn=get_selected_option, inputs=dropdown, outputs=option_output
)
# Accordion for Additional Information
with gr.Accordion("Additional Information"):
gr.Markdown(
"This interface demonstrates various Gradio components and layouts."
)
gr.Markdown(
"You can upload images, audio files, and interact with different components."
)
# Launch the application
if __name__ == "__main__":
demo.launch()
|