Xyro123 commited on
Commit
dcd2f32
Β·
verified Β·
1 Parent(s): 7a99175

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -50
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
 
3
  # --------------------------
4
- # SIMPLE AUTH DATABASE
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 back, **{username}**!"
14
  )
15
- return gr.update(), gr.update(), "❌ Invalid username or password."
16
 
17
  def signup(username, password):
18
  if username in users:
19
- return "⚠ User already exists!"
20
  users[username] = password
21
- return "βœ… Account created successfully! Please login now."
22
 
23
  # --------------------------
24
- # CHATBOT CORE
25
  # --------------------------
26
  def chat_bot(message, history):
27
  if history is None:
28
  history = []
29
 
30
  history.append({"role": "user", "content": message})
31
- bot_reply = "Hello! (Your bot response goes here...)"
32
-
33
- history.append({"role": "assistant", "content": bot_reply})
34
 
35
  return history, ""
36
 
37
  # --------------------------
38
- # CUSTOM CSS (CLEAN + MODERN)
39
  # --------------------------
40
  css = """
41
  body {
42
- background: #0d0d0d !important;
 
 
43
  font-family: 'Inter', sans-serif;
44
  }
45
 
 
 
 
 
 
 
 
 
46
  #main_title {
47
- color: #fff;
48
- font-size: 34px;
49
  text-align: center;
50
  font-weight: 800;
51
- margin-top: 40px;
52
  }
53
 
54
- .card-btn {
55
- background: #1a1a1a;
56
- border-radius: 16px;
57
- padding: 16px 22px !important;
 
58
  border: 1px solid #2a2a2a !important;
59
  color: #fff !important;
 
60
  font-size: 18px !important;
61
- transition: 0.18s ease;
62
  }
63
 
64
- .card-btn:hover {
65
  background: #242424 !important;
66
  transform: translateY(-2px);
67
  }
 
 
 
 
 
 
 
 
68
  """
69
 
70
  # --------------------------
71
- # UI & APP LAYOUT
72
  # --------------------------
73
  with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="blue", radius_size="md")) as app:
74
 
75
- # ============= LOGIN SCREEN ==============
76
  with gr.Group(visible=True) as login_screen:
77
- gr.Markdown("<h1 id='main_title'>Login to Continue</h1>")
78
 
79
  with gr.Tabs():
80
- # LOGIN TAB
81
  with gr.Tab("Login"):
82
- login_user = gr.Textbox(label="Username", placeholder="Enter username")
83
- login_pass = gr.Textbox(label="Password", type="password", placeholder="Enter password")
84
- login_btn = gr.Button("Login", variant="primary")
85
- login_status = gr.Markdown("")
86
 
87
- # SIGNUP TAB
88
  with gr.Tab("Sign Up"):
89
- sign_user = gr.Textbox(label="Create username")
90
- sign_pass = gr.Textbox(label="Create password", type="password")
91
- sign_btn = gr.Button("Create Account")
92
  signup_status = gr.Markdown("")
93
 
94
- # ============= MAIN APP ==============
95
- with gr.Group(visible=False) as home_screen:
96
 
97
  gr.Markdown("<h1 id='main_title'>What can I help you with?</h1>")
98
 
99
- # FEATURE BUTTONS
100
  with gr.Row():
101
- gr.Button("πŸ–Ό Create Image", elem_classes="card-btn")
102
- gr.Button("πŸ’» Code", elem_classes="card-btn")
103
 
104
  with gr.Row():
105
- gr.Button("πŸ“ Summarize Text", elem_classes="card-btn")
106
- gr.Button("πŸ’‘ Make a Plan", elem_classes="card-btn")
107
-
108
- gr.Markdown("<br>")
109
 
110
- # CHAT SECTION
111
- chatbot = gr.Chatbot(type="messages", height=450, label="Chat")
112
- message_box = gr.Textbox(placeholder="Ask me anything...", scale=8)
113
- send_btn = gr.Button("Send", scale=2)
114
 
115
- send_btn.click(chat_bot, [message_box, chatbot], [chatbot, message_box])
116
- message_box.submit(chat_bot, [message_box, chatbot], [chatbot, message_box])
117
 
118
- # BUTTON EVENTS
119
- login_btn.click(login, [login_user, login_pass], [login_screen, home_screen, login_status])
120
- sign_btn.click(signup, [sign_user, sign_pass], signup_status)
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()