pygwalker_test / app.py
outlier-winwin's picture
Update app.py
1e6c70e verified
import gradio as gr
import pygwalker as pyg
from datasets import load_dataset
# -----------------------------
# ๋ฐ์ดํ„ฐ & Pygwalker HTML
# -----------------------------
dataset = load_dataset("gradio/NYC-Airbnb-Open-Data", split="train")
df = dataset.to_pandas()
html = pyg.to_html(df, spec="./viz-config.json", spec_io_mode=False)
# -----------------------------
# ์‚ฌ์šฉ์ž ๊ณ„์ •
# -----------------------------
ACCOUNTS = {
"alice": "1234",
"bob": "qwerty",
"winwin": "mypassword"
}
def check_login(username, password):
if username in ACCOUNTS and ACCOUNTS[username] == password:
return (
gr.update(visible=True), # Pygwalker ํ™”๋ฉด ํ‘œ์‹œ
gr.update(visible=False), # ๋กœ๊ทธ์ธ ํ™”๋ฉด ์ˆจ๊น€
gr.update(visible=False), # ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ์ˆจ๊น€
)
else:
return (
gr.update(visible=False),
gr.update(visible=True),
gr.update(visible=True, value="โŒ ์‚ฌ์šฉ์ž๋ช… ๋˜๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค!"),
)
# -----------------------------
# Gradio UI
# -----------------------------
with gr.Blocks(css="""
/* ๋กœ๊ทธ์ธ ๋ฐ•์Šค */
.login-box {
background-color: #19254D; /* ์˜…์€ ํšŒ์ƒ‰ */
padding: 30px 25px;
border-radius: 12px;
margin: 40px auto;
display: flex;
flex-direction: column;
gap: 15px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
/* ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ */
.button-custom {
background-color: #87CEFA !important; /* ์—ฐํ•œ ํŒŒ๋ž‘ */
color: white !important;
font-weight: bold !important;
border-radius: 6px !important;
padding: 10px 0 !important;
font-size: 16px !important;
}
.button-custom span {
color: white !important;
}
.button-custom:hover {
background-color: #00BFFF !important;
color: white !important;
}
/* ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ */
.error-msg {
color: red;
text-align: center;
font-weight: bold;
}
/* Pygwalker ํ™”๋ฉด ์ค‘์•™ ์ •๋ ฌ */
.pygwalker-container {
max-width: 90%;
margin: 30px auto;
}
""") as demo:
# ๋กœ๊ทธ์ธ ํ™”๋ฉด
with gr.Group(visible=True, elem_classes="login-box") as login_box:
username_box = gr.Textbox(label="์‚ฌ์šฉ์ž๋ช…", placeholder="์•„์ด๋”” ์ž…๋ ฅ")
password_box = gr.Textbox(label="๋น„๋ฐ€๋ฒˆํ˜ธ", type="password", placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ")
submit_btn = gr.Button("๋กœ๊ทธ์ธ", elem_classes="button-custom")
error_msg = gr.Textbox(visible=False, interactive=False, label="", show_label=False, elem_classes="error-msg")
# Pygwalker ํ™”๋ฉด
pyg_html = gr.HTML(html, visible=False, elem_classes="pygwalker-container")
# ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ๋กœ๊ทธ์ธ ํ™•์ธ
submit_btn.click(
fn=check_login,
inputs=[username_box, password_box],
outputs=[pyg_html, login_box, error_msg]
)
demo.launch()