rapacious commited on
Commit
9395971
·
verified ·
1 Parent(s): befab1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -30
app.py CHANGED
@@ -1,33 +1,58 @@
1
- import gradio as gr
2
  import os
3
- from datetime import datetime
4
-
5
- # Danh sách các biến môi trường cần hiển thị
6
- firebase_keys = [
7
- "FIREBASE_API_KEY",
8
- "FIREBASE_URL"
9
- ]
10
-
11
- # Hàm hiển thị thời gian và các biến firebase
12
- def display_info():
13
- current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
14
-
15
- content = f"## ⏰ Thời gian hiện tại:\n{current_time}\n\n"
16
- content += "## 🔐 Danh sách các biến Firebase:\n"
17
-
18
- for key in firebase_keys:
19
- status = "✅ Đã lấy thành công" if os.getenv(key) else "❌ Chưa có"
20
- content += f"- **{key}**: {status}\n"
21
 
22
- return content
23
-
24
-
25
- with gr.Blocks() as demo:
26
- gr.Markdown("## Realtime Hiển thị Thời gian & Biến Firebase (Ẩn giá trị vì bảo mật)")
27
-
28
- output = gr.Markdown(display_info)
29
-
30
- # Auto Update sau 1s
31
- gr.Timer(display_info, every=1, outputs=output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- demo.launch()
 
 
 
1
  import os
2
+ from typing import Dict
3
+ import json
4
+ from prettytable import PrettyTable
5
+
6
+ class ConfigManager:
7
+ def __init__(self, firebase_api_key: str, firebase_url: str):
8
+ """Khởi tạo với 2 biến secret"""
9
+ self.config = {
10
+ "FIREBASE_API_KEY": firebase_api_key,
11
+ "FIREBASE_URL": firebase_url
12
+ }
 
 
 
 
 
 
 
13
 
14
+ def read_config(self) -> Dict:
15
+ """Đọc các biến hiện tại"""
16
+ return self.config
17
+
18
+ def update_config(self, key: str, value: str) -> bool:
19
+ """Cập nhật giá trị của biến"""
20
+ if key in self.config:
21
+ self.config[key] = value
22
+ return True
23
+ return False
24
+
25
+ def display_config(self):
26
+ """Hiển thị các biến một cách đẹp mắt"""
27
+ table = PrettyTable()
28
+ table.field_names = ["Variable", "Value"]
29
+ table.align["Variable"] = "l"
30
+ table.align["Value"] = "l"
31
+
32
+ for key, value in self.config.items():
33
+ table.add_row([key, value])
34
+
35
+ print("\nCurrent Configuration:")
36
+ print(table)
37
+
38
+ def main():
39
+ # Nhận giá trị ban đầu từ người dùng hoặc môi trường
40
+ api_key = os.environ.get("FIREBASE_API_KEY", "your_default_api_key")
41
+ url = os.environ.get("FIREBASE_URL", "your_default_url")
42
+
43
+ # Tạo instance của ConfigManager
44
+ config = ConfigManager(api_key, url)
45
+
46
+ # Hiển thị giá trị ban đầu
47
+ config.display_config()
48
+
49
+ # Ví dụ cập nhật giá trị
50
+ print("\nUpdating values...")
51
+ config.update_config("FIREBASE_API_KEY", "new_api_key_123")
52
+ config.update_config("FIREBASE_URL", "https://new-firebase-url.com")
53
+
54
+ # Hiển thị giá trị sau khi cập nhật
55
+ config.display_config()
56
 
57
+ if __name__ == "__main__":
58
+ main()