Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
# --------------------------
|
| 4 |
-
# SIMPLE AUTH
|
| 5 |
# --------------------------
|
| 6 |
users = {"admin": "1234"}
|
| 7 |
|
|
@@ -10,113 +10,128 @@ def login(username, password):
|
|
| 10 |
return (
|
| 11 |
gr.update(visible=False),
|
| 12 |
gr.update(visible=True),
|
| 13 |
-
f"β Welcome
|
| 14 |
)
|
| 15 |
-
return gr.update(), gr.update(), "β
|
| 16 |
|
| 17 |
def signup(username, password):
|
| 18 |
if username in users:
|
| 19 |
-
return "β
|
| 20 |
users[username] = password
|
| 21 |
-
return "β
Account created
|
| 22 |
|
| 23 |
# --------------------------
|
| 24 |
-
# CHATBOT
|
| 25 |
# --------------------------
|
| 26 |
def chat_bot(message, history):
|
| 27 |
if history is None:
|
| 28 |
history = []
|
| 29 |
|
| 30 |
history.append({"role": "user", "content": message})
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
history.append({"role": "assistant", "content": bot_reply})
|
| 34 |
|
| 35 |
return history, ""
|
| 36 |
|
| 37 |
# --------------------------
|
| 38 |
-
#
|
| 39 |
# --------------------------
|
| 40 |
css = """
|
| 41 |
body {
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
font-family: 'Inter', sans-serif;
|
| 44 |
}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
#main_title {
|
| 47 |
-
color:
|
| 48 |
-
font-size:
|
| 49 |
text-align: center;
|
| 50 |
font-weight: 800;
|
| 51 |
-
|
| 52 |
}
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
border: 1px solid #2a2a2a !important;
|
| 59 |
color: #fff !important;
|
|
|
|
| 60 |
font-size: 18px !important;
|
| 61 |
-
transition: 0.
|
| 62 |
}
|
| 63 |
|
| 64 |
-
.
|
| 65 |
background: #242424 !important;
|
| 66 |
transform: translateY(-2px);
|
| 67 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
"""
|
| 69 |
|
| 70 |
# --------------------------
|
| 71 |
-
# UI
|
| 72 |
# --------------------------
|
| 73 |
with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="blue", radius_size="md")) as app:
|
| 74 |
|
| 75 |
-
#
|
| 76 |
with gr.Group(visible=True) as login_screen:
|
| 77 |
-
gr.Markdown("<h1 id='main_title'>Login
|
| 78 |
|
| 79 |
with gr.Tabs():
|
| 80 |
-
# LOGIN TAB
|
| 81 |
with gr.Tab("Login"):
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
|
| 87 |
-
# SIGNUP TAB
|
| 88 |
with gr.Tab("Sign Up"):
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
signup_status = gr.Markdown("")
|
| 93 |
|
| 94 |
-
#
|
| 95 |
-
with gr.Group(visible=False) as
|
| 96 |
|
| 97 |
gr.Markdown("<h1 id='main_title'>What can I help you with?</h1>")
|
| 98 |
|
| 99 |
-
#
|
| 100 |
with gr.Row():
|
| 101 |
-
gr.Button("πΌ Create Image", elem_classes="
|
| 102 |
-
gr.Button("π» Code", elem_classes="
|
| 103 |
|
| 104 |
with gr.Row():
|
| 105 |
-
gr.Button("π Summarize Text", elem_classes="
|
| 106 |
-
gr.Button("π‘ Make a Plan", elem_classes="
|
| 107 |
-
|
| 108 |
-
gr.Markdown("<br>")
|
| 109 |
|
| 110 |
-
#
|
| 111 |
-
chatbot = gr.Chatbot(type="messages",
|
| 112 |
-
|
| 113 |
-
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
|
| 120 |
-
|
| 121 |
|
| 122 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
# --------------------------
|
| 4 |
+
# SIMPLE AUTH
|
| 5 |
# --------------------------
|
| 6 |
users = {"admin": "1234"}
|
| 7 |
|
|
|
|
| 10 |
return (
|
| 11 |
gr.update(visible=False),
|
| 12 |
gr.update(visible=True),
|
| 13 |
+
f"β Welcome, **{username}**!"
|
| 14 |
)
|
| 15 |
+
return gr.update(), gr.update(), "β Wrong username or password."
|
| 16 |
|
| 17 |
def signup(username, password):
|
| 18 |
if username in users:
|
| 19 |
+
return "β Username already exists!"
|
| 20 |
users[username] = password
|
| 21 |
+
return "β
Account created! You can log in now."
|
| 22 |
|
| 23 |
# --------------------------
|
| 24 |
+
# CHATBOT
|
| 25 |
# --------------------------
|
| 26 |
def chat_bot(message, history):
|
| 27 |
if history is None:
|
| 28 |
history = []
|
| 29 |
|
| 30 |
history.append({"role": "user", "content": message})
|
| 31 |
+
reply = "Hello! (Your bot response goes here...)"
|
| 32 |
+
history.append({"role": "assistant", "content": reply})
|
|
|
|
| 33 |
|
| 34 |
return history, ""
|
| 35 |
|
| 36 |
# --------------------------
|
| 37 |
+
# MODERN RESPONSIVE CSS
|
| 38 |
# --------------------------
|
| 39 |
css = """
|
| 40 |
body {
|
| 41 |
+
margin: 0 !important;
|
| 42 |
+
padding: 0 !important;
|
| 43 |
+
background: #0c0c0c;
|
| 44 |
font-family: 'Inter', sans-serif;
|
| 45 |
}
|
| 46 |
|
| 47 |
+
/* Make whole app fullscreen */
|
| 48 |
+
.gradio-container {
|
| 49 |
+
max-width: 100% !important;
|
| 50 |
+
width: 100% !important;
|
| 51 |
+
padding: 0 !important;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/* Title */
|
| 55 |
#main_title {
|
| 56 |
+
color: white;
|
| 57 |
+
font-size: 32px;
|
| 58 |
text-align: center;
|
| 59 |
font-weight: 800;
|
| 60 |
+
padding-top: 30px;
|
| 61 |
}
|
| 62 |
|
| 63 |
+
/* Buttons grid */
|
| 64 |
+
.feature-btn {
|
| 65 |
+
background: #1a1a1a !important;
|
| 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()
|