Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,137 +1,66 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# --------------------------
|
| 6 |
users = {"admin": "1234"}
|
| 7 |
|
| 8 |
-
def login(username, password):
|
| 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 |
-
border-radius: 14px !important;
|
| 67 |
-
padding: 18px !important;
|
| 68 |
-
border: 1px solid #2a2a2a !important;
|
| 69 |
-
color: #fff !important;
|
| 70 |
-
width: 100% !important;
|
| 71 |
-
font-size: 18px !important;
|
| 72 |
-
transition: 0.15s;
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
.feature-btn:hover {
|
| 76 |
-
background: #242424 !important;
|
| 77 |
-
transform: translateY(-2px);
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
/* Chatbot panel fullscreen */
|
| 81 |
-
.chat-container {
|
| 82 |
-
width: 100% !important;
|
| 83 |
-
height: calc(100vh - 320px);
|
| 84 |
-
margin-top: 20px;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
"""
|
| 88 |
-
|
| 89 |
-
# --------------------------
|
| 90 |
-
# UI
|
| 91 |
-
# --------------------------
|
| 92 |
-
with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="blue", radius_size="md")) as app:
|
| 93 |
-
|
| 94 |
-
# LOGIN SCREEN
|
| 95 |
-
with gr.Group(visible=True) as login_screen:
|
| 96 |
-
gr.Markdown("<h1 id='main_title'>Login</h1>")
|
| 97 |
-
|
| 98 |
-
with gr.Tabs():
|
| 99 |
-
with gr.Tab("Login"):
|
| 100 |
-
u = gr.Textbox(label="Username")
|
| 101 |
-
p = gr.Textbox(label="Password", type="password")
|
| 102 |
-
b = gr.Button("Login", variant="primary")
|
| 103 |
-
status = gr.Markdown("")
|
| 104 |
-
|
| 105 |
-
with gr.Tab("Sign Up"):
|
| 106 |
-
su = gr.Textbox(label="New Username")
|
| 107 |
-
sp = gr.Textbox(label="New Password", type="password")
|
| 108 |
-
sb = gr.Button("Create Account")
|
| 109 |
-
signup_status = gr.Markdown("")
|
| 110 |
-
|
| 111 |
-
# MAIN SCREEN
|
| 112 |
-
with gr.Group(visible=False) as home:
|
| 113 |
-
|
| 114 |
-
gr.Markdown("<h1 id='main_title'>What can I help you with?</h1>")
|
| 115 |
-
|
| 116 |
-
# Feature buttons (full width)
|
| 117 |
-
with gr.Row():
|
| 118 |
-
gr.Button("πΌ Create Image", elem_classes="feature-btn")
|
| 119 |
-
gr.Button("π» Code", elem_classes="feature-btn")
|
| 120 |
-
|
| 121 |
-
with gr.Row():
|
| 122 |
-
gr.Button("π Summarize Text", elem_classes="feature-btn")
|
| 123 |
-
gr.Button("π‘ Make a Plan", elem_classes="feature-btn")
|
| 124 |
-
|
| 125 |
-
# Chatbot FULLSCREEN
|
| 126 |
-
chatbot = gr.Chatbot(type="messages", elem_classes="chat-container")
|
| 127 |
-
msg = gr.Textbox(placeholder="Ask me anythingβ¦")
|
| 128 |
-
send = gr.Button("Send", variant="primary")
|
| 129 |
-
|
| 130 |
-
send.click(chat_bot, [msg, chatbot], [chatbot, msg])
|
| 131 |
-
msg.submit(chat_bot, [msg, chatbot], [chatbot, msg])
|
| 132 |
-
|
| 133 |
-
# Button events
|
| 134 |
-
b.click(login, [u, p], [login_screen, home, status])
|
| 135 |
-
sb.click(signup, [su, sp], signup_status)
|
| 136 |
|
| 137 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
----------------- SIMPLE AUTH SYSTEM -----------------
|
| 4 |
+
|
|
|
|
| 5 |
users = {"admin": "1234"}
|
| 6 |
|
| 7 |
+
def login(username, password): if username in users and users[username] == password: return gr.update(visible=False), gr.update(visible=True), f"Welcome, {username}!" return gr.update(), gr.update(), "β Invalid credentials!"
|
| 8 |
+
|
| 9 |
+
def signup(username, password): if username in users: return "β User already exists!" users[username] = password return "β
Account created! You can now log in."
|
| 10 |
+
|
| 11 |
+
----------------- CHATBOT FUNCTION -----------------
|
| 12 |
+
|
| 13 |
+
def chat_bot(msg, history): history = history + [(msg, "β¨ Your bot reply will appear here...")] return history, history
|
| 14 |
+
|
| 15 |
+
----------------- CUSTOM CSS (Clean Modern UI) -----------------
|
| 16 |
+
|
| 17 |
+
css = """ body { background: #0d0d0d; font-family: Inter, sans-serif; } #main_title { color: white; text-align: center; margin-top: 40px; font-size: 36px; font-weight: 900; }
|
| 18 |
+
|
| 19 |
+
.card-btn { background: linear-gradient(145deg, #1a1a1a, #111); border-radius: 20px; padding: 18px; border: 1px solid #2a2a2a; color: white; font-size: 18px; width: 100%; transition: 0.25s; } .card-btn:hover { background: #222; transform: translateY(-3px); } .chatbox-holder { border-radius: 18px; overflow: hidden; } """
|
| 20 |
+
|
| 21 |
+
----------------- APP UI -----------------
|
| 22 |
+
|
| 23 |
+
with gr.Blocks(css=css, theme="soft") as app:
|
| 24 |
+
|
| 25 |
+
# -------- AUTH SCREEN --------
|
| 26 |
+
with gr.Group(visible=True) as auth_screen:
|
| 27 |
+
gr.Markdown("<h1 id='main_title'>Welcome</h1>")
|
| 28 |
+
|
| 29 |
+
with gr.Tabs():
|
| 30 |
+
with gr.Tab("Login"):
|
| 31 |
+
login_user = gr.Textbox(label="Username")
|
| 32 |
+
login_pass = gr.Textbox(label="Password", type="password")
|
| 33 |
+
login_btn = gr.Button("Log In")
|
| 34 |
+
login_status = gr.Markdown("")
|
| 35 |
+
|
| 36 |
+
with gr.Tab("Sign Up"):
|
| 37 |
+
sign_user = gr.Textbox(label="New Username")
|
| 38 |
+
sign_pass = gr.Textbox(label="New Password", type="password")
|
| 39 |
+
sign_btn = gr.Button("Create Account")
|
| 40 |
+
signup_status = gr.Markdown("")
|
| 41 |
+
|
| 42 |
+
# -------- MAIN HOME SCREEN --------
|
| 43 |
+
with gr.Group(visible=False) as home_screen:
|
| 44 |
+
|
| 45 |
+
gr.Markdown("<h1 id='main_title'>What can I help you with?</h1>")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
gr.Button("π¨ Create Image", elem_classes="card-btn")
|
| 49 |
+
gr.Button("π» Write Code", elem_classes="card-btn")
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
gr.Button("π Summarize Text", elem_classes="card-btn")
|
| 53 |
+
gr.Button("π
Make a Plan", elem_classes="card-btn")
|
| 54 |
+
|
| 55 |
+
chatbot = gr.Chatbot(height=450, elem_classes="chatbox-holder")
|
| 56 |
+
msg = gr.Textbox(placeholder="Ask something...", scale=8)
|
| 57 |
+
send = gr.Button("Send", scale=2)
|
| 58 |
+
|
| 59 |
+
send.click(chat_bot, [msg, chatbot], [chatbot, chatbot])
|
| 60 |
+
msg.submit(chat_bot, [msg, chatbot], [chatbot, chatbot])
|
| 61 |
+
|
| 62 |
+
# -------- BUTTON EVENTS --------
|
| 63 |
+
login_btn.click(login, [login_user, login_pass], [auth_screen, home_screen, login_status])
|
| 64 |
+
sign_btn.click(signup, [sign_user, sign_pass], signup_status)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
app.launch()
|