Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def process_text(text):
|
| 6 |
+
return f"You said: {text}"
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def flip_image(image):
|
| 10 |
+
return np.fliplr(image)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def process_audio(audio):
|
| 14 |
+
return f"Received audio file: {audio[0]}"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def get_selected_option(option):
|
| 18 |
+
return f"You selected: {option}"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
with gr.Blocks() as demo:
|
| 22 |
+
# Markdown Header
|
| 23 |
+
gr.Markdown("# Comprehensive Gradio Interface")
|
| 24 |
+
|
| 25 |
+
# Row and Column Layout for Text Processing
|
| 26 |
+
with gr.Row():
|
| 27 |
+
with gr.Column():
|
| 28 |
+
with gr.Group(): # Group for Text Input
|
| 29 |
+
text_input = gr.Textbox(
|
| 30 |
+
label="Enter Text", placeholder="Type something..."
|
| 31 |
+
)
|
| 32 |
+
submit_btn = gr.Button("Submit")
|
| 33 |
+
with gr.Column():
|
| 34 |
+
text_output = gr.Textbox(label="Output", interactive=False)
|
| 35 |
+
|
| 36 |
+
# Button click event for text processing
|
| 37 |
+
submit_btn.click(fn=process_text, inputs=text_input, outputs=text_output)
|
| 38 |
+
|
| 39 |
+
# Tab Layout
|
| 40 |
+
with gr.Tabs():
|
| 41 |
+
with gr.Tab("Image Flipper"):
|
| 42 |
+
image_input = gr.Image(type="numpy", label="Upload Image")
|
| 43 |
+
image_output = gr.Image(label="Flipped Image")
|
| 44 |
+
flip_btn = gr.Button("Flip Image")
|
| 45 |
+
flip_btn.click(fn=flip_image, inputs=image_input, outputs=image_output)
|
| 46 |
+
|
| 47 |
+
with gr.Tab("Audio Processor"):
|
| 48 |
+
audio_input = gr.Audio(label="Upload Audio")
|
| 49 |
+
audio_output = gr.Textbox(label="Audio Output", interactive=False)
|
| 50 |
+
audio_btn = gr.Button("Process Audio")
|
| 51 |
+
audio_btn.click(fn=process_audio, inputs=audio_input, outputs=audio_output)
|
| 52 |
+
|
| 53 |
+
with gr.Tab("Options"):
|
| 54 |
+
dropdown = gr.Dropdown(
|
| 55 |
+
choices=["Option 1", "Option 2", "Option 3"], label="Choose an Option"
|
| 56 |
+
)
|
| 57 |
+
option_output = gr.Textbox(label="Selected Option", interactive=False)
|
| 58 |
+
dropdown.change(
|
| 59 |
+
fn=get_selected_option, inputs=dropdown, outputs=option_output
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Accordion for Additional Information
|
| 63 |
+
with gr.Accordion("Additional Information"):
|
| 64 |
+
gr.Markdown(
|
| 65 |
+
"This interface demonstrates various Gradio components and layouts."
|
| 66 |
+
)
|
| 67 |
+
gr.Markdown(
|
| 68 |
+
"You can upload images, audio files, and interact with different components."
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Launch the application
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
demo.launch()
|