rapacious commited on
Commit
6690bf8
·
verified ·
1 Parent(s): a4af348

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -22
app.py CHANGED
@@ -1,23 +1,34 @@
1
- # This is a simple Gradio app that translates Vietnamese to English using a pre-trained model.
2
  import gradio as gr
3
- from transformers_js_py import pipeline # Assuming transformers_js_py is a valid library for this example
4
-
5
- # Define a function that takes Vietnamese text and returns the English translation.
6
- def translate_vi2en(vi_text):
7
- translator = pipeline("translation_vi_to_en")
8
- translation = translator(vi_text)[0]['translation_text']
9
- return translation
10
-
11
- # Create a Gradio interface that takes a textbox input, runs it through the translate function, and returns output to a textbox.
12
- demo = gr.Interface(
13
- fn=translate_vi2en,
14
- inputs=gr.Textbox(label="Nhập văn bản tiếng Việt"),
15
- outputs=gr.Textbox(label="Dịch sang tiếng Anh"),
16
- title="Việt Nam sang Anh Translator",
17
- description="Nhập văn bản tiếng Việt nhận kết quả dịch sang tiếng Anh.",
18
- theme=gr.themes.Default() # Use a default theme for a clean and modern look
19
- )
20
-
21
- # Launch the interface.
22
- if __name__ == "__main__":
23
- demo.launch(show_error=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import os
3
+ import time
4
+ from datetime import datetime
5
+
6
+ # Đọc firebase api key & url từ biến môi trường
7
+ FIREBASE_API_KEY = os.getenv("FIREBASE_API_KEY", "Not Found")
8
+ FIREBASE_URL = os.getenv("FIREBASE_URL", "Not Found")
9
+
10
+ # Ghép lại thành dict dễ show
11
+ firebase_info = {
12
+ "FIREBASE_API_KEY": FIREBASE_API_KEY,
13
+ "FIREBASE_URL": FIREBASE_URL
14
+ }
15
+
16
+ # Hàm cập nhật thời gian + show firebase info
17
+ def display_info():
18
+ current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
19
+ content = f"### ⏰ Thời gian hiện tại:\n{current_time}\n\n"
20
+ content += "### 🔐 Thông tin Firebase (từ Huggingface Secret):\n"
21
+ for key, value in firebase_info.items():
22
+ content += f"- **{key}**: {value}\n"
23
+ return content
24
+
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown("## Demo Thời gian & Firebase Variables từ Huggingface Secret")
27
+
28
+ output = gr.Markdown(display_info)
29
+
30
+ refresh_btn = gr.Button("🔄 Refresh")
31
+
32
+ refresh_btn.click(fn=display_info, outputs=output)
33
+
34
+ demo.launch()