Spaces:
Running
Running
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() | |