Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,58 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 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 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
| 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()
|