Xyro123 commited on
Commit
36fa7f6
Β·
verified Β·
1 Parent(s): dcd2f32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -131
app.py CHANGED
@@ -1,137 +1,66 @@
1
  import gradio as gr
2
 
3
- # --------------------------
4
- # SIMPLE AUTH
5
- # --------------------------
6
  users = {"admin": "1234"}
7
 
8
- def login(username, password):
9
- if username in users and users[username] == password:
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()
 
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()