File size: 5,595 Bytes
1ab2dae 1f5df60 75b3700 5151139 fcce2d7 1ab2dae fcce2d7 40d56e9 1ab2dae 40d56e9 1ab2dae ba38f5c fcce2d7 ba38f5c 1ab2dae 75b3700 1ab2dae 75b3700 1ab2dae fcce2d7 1ab2dae fcce2d7 1ab2dae 40d56e9 1ab2dae fcce2d7 1ab2dae fcce2d7 1ab2dae fcce2d7 1ab2dae 75b3700 1ab2dae fcce2d7 1ab2dae 75b3700 1ab2dae fcce2d7 1ab2dae 75547e4 1ab2dae fcce2d7 1ab2dae 1eb2326 75b3700 fcce2d7 |
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
import time
import os
import gradio as gr
# Заметка: функция create_theme_dropdown не является частью официального API Gradio,
# и может быть удалена или изменена. Этот код может потребовать обновления в будущем.
THEME = os.getenv("THEME") # Установка значения по умолчанию для THEME
with gr.Blocks(theme=THEME) as demo:
with gr.Row().style(equal_height=True):
with gr.Column(scale=10):
gr.Markdown(
f"""
# Theme preview: `{THEME}`
To use this theme, set `theme='{THEME}'` in `gr.Blocks()` or `gr.Interface()`.
You can append an `@` and a semantic version expression, e.g. @>=1.0.0,<2.0.0 to pin to a given version
of this theme.
"""
)
with gr.Column(scale=3):
with gr.Box():
with gr.Column():
# Так как create_theme_dropdown не является частью официального API,
# предполагается, что dropdown является объектом gr.Dropdown
dropdown = gr.Dropdown(["Default", "Huggingface", "Dark"], label="Choose Theme")
toggle_dark = gr.Button(value="Toggle Dark").style(full_width=True)
name = gr.Textbox(
label="Name",
info="Full name, including middle name. No special characters.",
placeholder="John Doe",
value="John Doe",
interactive=True,
)
with gr.Row():
slider1 = gr.Slider(label="Slider 1")
slider2 = gr.Slider(label="Slider 2")
gr.CheckboxGroup(["A", "B", "C"], label="Checkbox Group")
with gr.Row():
with gr.Column(variant="panel", scale=1):
gr.Markdown("## Panel 1")
radio = gr.Radio(
["A", "B", "C"],
label="Radio",
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.",
)
drop = gr.Dropdown(["Option 1", "Option 2", "Option 3"], show_label=False)
drop_2 = gr.Dropdown(
["Option A", "Option B", "Option C"],
multiselect=True,
value=["Option A"],
label="Dropdown",
interactive=True,
)
check = gr.Checkbox(label="Go")
with gr.Column(variant="panel", scale=2):
img = gr.Image(
label="Image"
).style(height=320)
with gr.Row():
go_btn = gr.Button("Go", variant="primary")
clear_btn = gr.Button("Clear", variant="secondary")
def go(*args):
time.sleep(3)
return f"https://huggingface.co/spaces/{THEME}/resolve/main/header-image.jpg"
go_btn.click(go, inputs=[radio, drop, drop_2, check, name], outputs=img)
def clear():
time.sleep(0.2)
return None
clear_btn.click(clear, inputs=None, outputs=img)
with gr.Row():
btn1 = gr.Button("Button 1").style(size="sm")
btn2 = gr.File().style(size="sm", full_width=False) # Используйте gr.File вместо gr.UploadButton
stop_btn = gr.Button("Stop", variant="stop").style(size="sm")
with gr.Row():
gr.Dataframe(value=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], label="Dataframe")
gr.JSON(
value={"a": 1, "b": 2, "c": {"test": "a", "test2": [1, 2, 3]}}, label="JSON"
)
# Используйте gr.Label для отображения текста, а не для отображения объекта
gr.Label(value="Cat: 0.7, Dog: 0.2, Fish: 0.1")
gr.File()
with gr.Row():
gr.ColorPicker()
gr.Video("https://gradio-static-files.s3.us-west-2.amazonaws.com/world.mp4")
gr.Gallery(
[
"https://gradio-static-files.s3.us-west-2.amazonaws.com/lion.jpg",
"https://gradio-static-files.s3.us-west-2.amazonaws.com/logo.png",
"https://gradio-static-files.s3.us-west-2.amazonaws.com/tower.jpg",
]
).style(height="200px", grid=2)
with gr.Row():
with gr.Column(scale=2):
chatbot = gr.Chatbot([("Hello", "Hi")], label="Chatbot")
chat_btn = gr.Button("Add messages")
def chat(history):
time.sleep(2)
return history + [["How are you?", "I am good."]]
chat_btn.click(chat, inputs=[chatbot], outputs=chatbot)
with gr.Column(scale=1):
with gr.Accordion("Advanced Settings"):
gr.Markdown("Hello")
gr.Number(label="Chatbot control 1")
gr.Number(label="Chatbot control 2")
gr.Number(label="Chatbot control 3")
# Это действие должно быть реализовано внутри обработчика событий кнопки
dropdown.change(None, dropdown, None, _js=js)
toggle_dark.click(
None,
_js="""
() => {
document.body.classList.toggle('dark');
}
""",
)
if __name__ == "__main__":
demo.launch() |