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