Movajao commited on
Commit
ef43cdb
·
verified ·
1 Parent(s): 7079077

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -9
app.py CHANGED
@@ -3,18 +3,82 @@ from datetime import datetime
3
 
4
  logs = []
5
 
 
6
  def login(name):
7
- t = datetime.now().strftime("%H:%M:%S")
8
- msg = f"[{t}] {name} has logged in."
9
- print(msg) # HF container logs
10
- logs.append(msg) # Display in UI
 
 
 
 
 
 
 
 
11
  return "\n".join(logs)
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  with gr.Blocks() as demo:
14
- name = gr.Textbox()
15
- terminal = gr.Textbox(lines=15)
16
- btn = gr.Button("Login")
17
 
18
- btn.click(login, inputs=name, outputs=terminal)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- demo.launch()
 
3
 
4
  logs = []
5
 
6
+
7
  def login(name):
8
+
9
+ if not name:
10
+ name = "Unknown"
11
+
12
+ now = datetime.now().strftime("%H:%M:%S")
13
+
14
+ message = f"[{now}] {name} has logged in."
15
+
16
+ print(message)
17
+
18
+ logs.append(message)
19
+
20
  return "\n".join(logs)
21
 
22
+
23
+ def refresh():
24
+ if logs:
25
+ return "\n".join(logs)
26
+ return "=== Waiting for users... ==="
27
+
28
+
29
+ css = """
30
+ body{
31
+ background:#e8ecf2;
32
+ }
33
+
34
+ .gradio-container{
35
+ background:#e8ecf2 !important;
36
+ }
37
+
38
+ button{
39
+ border-radius:15px !important;
40
+ }
41
+
42
+ textarea{
43
+ background:#111111 !important;
44
+ color:#00ff66 !important;
45
+ font-family:Consolas, monospace !important;
46
+ font-size:15px !important;
47
+ }
48
+ """
49
+
50
  with gr.Blocks() as demo:
 
 
 
51
 
52
+ gr.Markdown("# 🖥️ User Login Monitor")
53
+
54
+ with gr.Row():
55
+
56
+ username = gr.Textbox(
57
+ label="User",
58
+ placeholder="Jason"
59
+ )
60
+
61
+ login_btn = gr.Button("Login")
62
+
63
+ terminal = gr.Textbox(
64
+ label="Terminal",
65
+ value="=== SERVER STARTED ===",
66
+ lines=18,
67
+ interactive=False
68
+ )
69
+
70
+ refresh_btn = gr.Button("Refresh Logs")
71
+
72
+ login_btn.click(
73
+ fn=login,
74
+ inputs=username,
75
+ outputs=terminal,
76
+ api_name="login"
77
+ )
78
+
79
+ refresh_btn.click(
80
+ fn=refresh,
81
+ outputs=terminal
82
+ )
83
 
84
+ demo.launch(css=css)