Su189 commited on
Commit
59b91f3
·
verified ·
1 Parent(s): eec1118

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import time
4
+
5
+ # Load config
6
+ with open("config_demo.json", "r", encoding="utf-8") as f:
7
+ config = json.load(f)
8
+
9
+ FREE_QUOTA = config["free_quota"]
10
+
11
+ user_used_chars = 0 # Demo: lưu tạm local
12
+
13
+ def check_and_update(text):
14
+ global user_used_chars
15
+ input_len = len(text)
16
+
17
+ if user_used_chars + input_len > FREE_QUOTA:
18
+ return None, f"🚫 Vượt quá giới hạn {FREE_QUOTA:,} ký tự dùng thử"
19
+
20
+ user_used_chars += input_len
21
+
22
+ # Tạm xử lý clone/TTS: giả lập 6 giây chờ GPU
23
+ time.sleep(2)
24
+ return "✅ Xử lý thành công (Demo Placeholder)", f"Đã dùng: {user_used_chars:,}/{FREE_QUOTA:,} ký tự"
25
+
26
+ def update_counter(text):
27
+ char_count = len(text)
28
+ status = f"{char_count:,}/{FREE_QUOTA:,} ký tự"
29
+ css_class = "char-limit-ok" if char_count <= FREE_QUOTA else "char-limit-over"
30
+ return f'<span class="{css_class}">{status}</span>'
31
+
32
+ with gr.Blocks(css="styles.css", title="AVATabs Demo") as demo:
33
+
34
+ # HEADER
35
+ with gr.Row():
36
+ gr.Markdown('<div id="header-title">🎯 AVATabs <span id="demo-badge">Demo</span></div>')
37
+
38
+ # INPUT TEXT
39
+ input_text = gr.Textbox(lines=10, placeholder="Nhập nội dung...", label="Nhập Textbox")
40
+
41
+ char_counter = gr.HTML('<div id="char-counter">0 ký tự</div>')
42
+ input_text.change(fn=update_counter, inputs=input_text, outputs=char_counter)
43
+
44
+ with gr.Tab("Clone"):
45
+ btn_clone = gr.Button("Bắt đầu Clone")
46
+ output_clone = gr.Textbox(label="Kết quả Demo")
47
+ msg_clone = gr.Markdown()
48
+ btn_clone.click(fn=check_and_update, inputs=input_text, outputs=[output_clone, msg_clone])
49
+
50
+ with gr.Tab("TTS"):
51
+ btn_tts = gr.Button("Chuyển văn bản thành giọng nói")
52
+ output_tts = gr.Textbox(label="Kết quả Demo")
53
+ msg_tts = gr.Markdown()
54
+ btn_tts.click(fn=check_and_update, inputs=input_text, outputs=[output_tts, msg_tts])
55
+
56
+ demo.launch()