| import gradio as gr |
| import numpy as np |
|
|
| |
| def handle_image_editor(image): |
| |
| return image |
|
|
| |
| def handle_chatbox(message, history): |
| |
| response = "Echo: " + message |
| history.append({"role": "user", "content": message}) |
| history.append({"role": "assistant", "content": response}) |
| return "", history |
|
|
| |
| def handle_prompt_box(prompt, image_generation, checkboxes, slider): |
| |
| return f"Prompt: {prompt}, Image Generation: {image_generation}, Checkboxes: {checkboxes}, Slider: {slider}" |
|
|
| |
| def handle_accordions(model, api, settings): |
| |
| return f"Model: {model}, API: {api}, Settings: {settings}" |
|
|
| |
| with gr.Blocks(css=""" |
| :root { |
| --primary-800: #1f2937; |
| --secondary-500: #3b82f6; |
| --text-color: #000000; |
| --radius-sm: 8px; |
| } |
| .gr-button { |
| background-color: var(--secondary-500); |
| color: var(--text-color); |
| border-radius: var(--radius-sm); |
| } |
| .gr-button:hover { |
| background-color: #2563eb; |
| } |
| .gr-button:active { |
| background-color: #1d4ed8; |
| } |
| .gr-button:disabled { |
| background-color: #c7d2fe; |
| color: #6b7280; |
| } |
| .gr-button--icon { |
| padding: 0.5rem; |
| } |
| .gr-button--icon img { |
| width: 1rem; |
| height: 1rem; |
| } |
| .gr-image-editor { |
| border: 1px solid var(--secondary-500); |
| border-radius: var(--radius-sm); |
| } |
| .gr-gallery { |
| border: 1px solid var(--secondary-500); |
| border-radius: var(--radius-sm); |
| } |
| .gr-chatbot { |
| border: 1px solid var(--secondary-500); |
| border-radius: var(--radius-sm); |
| } |
| .gr-accordion { |
| border: 1px solid var(--secondary-500); |
| border-radius: var(--radius-sm); |
| } |
| """) as demo: |
| |
| with gr.Row(): |
| with gr.Column(): |
| hamburger_btn = gr.Button("Hamburger", elem_classes="gr-button--icon") |
| hamburger_btn.click(lambda: gr.Info("Hamburger button clicked"), None, None) |
| color_picker = gr.ColorPicker(value="#3b82f6", label="Color Picker", show_label=False) |
| toggle_dark = gr.Button("Toggle Dark", elem_classes="gr-button--icon") |
| toggle_dark.click(lambda: gr.Info("Dark mode toggled"), None, None) |
|
|
| |
| with gr.Row(): |
| with gr.Column(): |
| image_editor = gr.ImageEditor(type="numpy", label="Image Editor", show_download_button=True) |
| image = gr.Image(type="numpy", label="Image", show_download_button=True) |
| gallery = gr.Gallery(columns=4, label="Gallery", show_download_button=True) |
|
|
| |
| with gr.Row(): |
| with gr.Column(): |
| chatbox = gr.Chatbot(type="messages", label="Chatbox") |
| msg = gr.Textbox(label="Message") |
| msg.submit(handle_chatbox, [msg, chatbox], [msg, chatbox]) |
|
|
| |
| with gr.Row(): |
| with gr.Column(): |
| prompt_box = gr.Textbox(label="Prompt") |
| image_generation = gr.Checkbox(label="Image Generation") |
| checkboxes = gr.CheckboxGroup(["Checkbox 1", "Checkbox 2", "Checkbox 3"], label="Checkboxes") |
| slider = gr.Slider(0, 100, step=1, label="Slider") |
| prompt_box.submit(handle_prompt_box, [prompt_box, image_generation, checkboxes, slider], None) |
|
|
| |
| with gr.Row(): |
| with gr.Column(): |
| model_accordion = gr.Accordion("Model", open=False) |
| with model_accordion: |
| model |