CoolFace
Apppublic

Medguy/base2

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py147 linesDownload Raw Back to root
1import time2 3import gradio as gr4from gradio.themes.utils.theme_dropdown import create_theme_dropdown5 6dropdown, js = create_theme_dropdown()7 8with gr.Blocks(theme='Medguy/base2') as demo:9    with gr.Row().style(equal_height=True):10        with gr.Column(scale=10):11            gr.Markdown(12                """13                # Theme preview: `base2`14                To use this theme, set `theme='Medguy/base2'` in `gr.Blocks()` or `gr.Interface()`.15                You can append an `@` and a semantic version expression, e.g. @>=1.0.0,<2.0.0 to pin to a given version16                of this theme.17                """18            )19        with gr.Column(scale=3):20            with gr.Box():21                dropdown.render()22                toggle_dark = gr.Button(value="Toggle Dark").style(full_width=True)23 24    dropdown.change(None, dropdown, None, _js=js)25    toggle_dark.click(26        None,27        _js="""28        () => {29            document.body.classList.toggle('dark');30        }31        """,32    )33 34    name = gr.Textbox(35        label="Name",36        info="Full name, including middle name. No special characters.",37        placeholder="John Doe",38        value="John Doe",39        interactive=True,40    )41 42    with gr.Row():43        slider1 = gr.Slider(label="Slider 1")44        slider2 = gr.Slider(label="Slider 2")45    gr.CheckboxGroup(["A", "B", "C"], label="Checkbox Group")46 47    with gr.Row():48        with gr.Column(variant="panel", scale=1):49            gr.Markdown("## Panel 1")50            radio = gr.Radio(51                ["A", "B", "C"],52                label="Radio",53                info="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",54            )55            drop = gr.Dropdown(["Option 1", "Option 2", "Option 3"], show_label=False)56            drop_2 = gr.Dropdown(57                ["Option A", "Option B", "Option C"],58                multiselect=True,59                value=["Option A"],60                label="Dropdown",61                interactive=True,62            )63            check = gr.Checkbox(label="Go")64        with gr.Column(variant="panel", scale=2):65            img = gr.Image(66                "https://gradio-static-files.s3.us-west-2.amazonaws.com/header-image.jpg",67                label="Image",68            ).style(height=320)69            with gr.Row():70                go_btn = gr.Button("Go", label="Primary Button", variant="primary")71                clear_btn = gr.Button(72                    "Clear", label="Secondary Button", variant="secondary"73                )74 75                def go(*args):76                    time.sleep(3)77                    return "https://gradio-static-files.s3.us-west-2.amazonaws.com/header-image.jpgjpg"78 79                go_btn.click(go, [radio, drop, drop_2, check, name], img, api_name="go")80 81                def clear():82                    time.sleep(0.2)83                    return None84 85                clear_btn.click(clear, None, img)86 87            with gr.Row():88                btn1 = gr.Button("Button 1").style(size="sm")89                btn2 = gr.UploadButton().style(size="sm")90                stop_btn = gr.Button("Stop", label="Stop Button", variant="stop").style(91                    size="sm"92                )93 94    with gr.Row():95        gr.Dataframe(value=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], label="Dataframe")96        gr.JSON(97            value={"a": 1, "b": 2, "c": {"test": "a", "test2": [1, 2, 3]}}, label="JSON"98        )99        gr.Label(value={"cat": 0.7, "dog": 0.2, "fish": 0.1})100        gr.File()101    with gr.Row():102        gr.ColorPicker()103        gr.Video("https://gradio-static-files.s3.us-west-2.amazonaws.com/world.mp4")104        gr.Gallery(105            [106                (107                    "https://gradio-static-files.s3.us-west-2.amazonaws.com/lion.jpg",108                    "lion",109                ),110                (111                    "https://gradio-static-files.s3.us-west-2.amazonaws.com/logo.png",112                    "logo",113                ),114                (115                    "https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpg",116                    "tower",117                ),118            ]119        ).style(height="200px", grid=2)120 121    with gr.Row():122        with gr.Column(scale=2):123            chatbot = gr.Chatbot([("Hello", "Hi")], label="Chatbot")124            chat_btn = gr.Button("Add messages")125 126            def chat(history):127                time.sleep(2)128                yield [["How are you?", "I am good."]]129 130            chat_btn.click(131                lambda history: history132                + [["How are you?", "I am good."]]133                + (time.sleep(2) or []),134                chatbot,135                chatbot,136            )137        with gr.Column(scale=1):138            with gr.Accordion("Advanced Settings"):139                gr.Markdown("Hello")140                gr.Number(label="Chatbot control 1")141                gr.Number(label="Chatbot control 2")142                gr.Number(label="Chatbot control 3")143 144 145if __name__ == "__main__":146    demo.queue().launch()147