AbuAlone09 commited on
Commit
30aa2b8
·
verified ·
1 Parent(s): 11b18a1

Update webui/run_app.py

Browse files
Files changed (1) hide show
  1. webui/run_app.py +12 -86
webui/run_app.py CHANGED
@@ -1,5 +1,5 @@
1
  # =========================================================
2
- # VERSION 2.5.1 - FIX LIVE LOG STREAMING (AUTO-SCROLL)
3
  # =========================================================
4
 
5
  import os
@@ -38,33 +38,34 @@ def get_voice_list():
38
  except: pass
39
  return ["vi-VN-HoaiMyNeural", "en-US-AvaNeural"]
40
 
41
- # --- 2. CSS CUSTOM (FIXED LOG BOX & NO BORDERS) ---
42
  CSS = """
43
  .main-title { font-size: 32px; font-weight: 800; text-align: center; color: #ffffff; margin-bottom: 20px; }
44
  .gen-btn { background-color: #28a745 !important; border: none !important; color: white !important; font-weight: bold !important; height: 50px !important; border-radius: 8px !important; }
45
  .footer-container { text-align: center; color: #666; margin-top: 20px; font-size: 12px; }
46
- .console-log { font-family: 'Courier New', Courier, monospace !important; font-size: 13px !important; background: #080808 !important; color: #00ff41 !important; border: 1px solid #222 !important; }
47
  .vip-input input { border-bottom: 2px solid #ffd700 !important; border-top: none !important; border-left: none !important; border-right: none !important; background: transparent !important; }
48
  .gradio-container { background-color: #0b0f19 !important; }
49
  .gradio-group { border: none !important; box-shadow: none !important; background: transparent !important; }
50
  """
51
 
52
- # --- 3. LOGIC XỬ LIVE LOG STREAMING ---
53
  @spaces.GPU(duration=120)
54
  def handle_rendering(video_script, clip_duration, voice_rate, selected_voice, enable_subtitles, enable_bgm, user_key):
55
  if not video_script:
56
- raise gr.Error("Vui lòng nhập kịch bản!")
57
 
58
  is_vip = (user_key.strip() == VIP_KEY and VIP_KEY != "")
59
  task_id = str(uuid4())
60
- full_logs = []
61
 
62
  def stream_log(msg, level="INFO"):
63
  ts = time.strftime("%H:%M:%S")
64
- new_entry = f"[{ts}] {level}: {msg}"
65
- full_logs.append(new_entry)
66
- # Chỉ hiển thị 2 dòng mới nhất trong bảng log UI
67
- return "\n".join(full_logs[-2:])
 
68
 
69
  params = VideoParams(
70
  video_subject=video_script[:30].strip(),
@@ -75,79 +76,4 @@ def handle_rendering(video_script, clip_duration, voice_rate, selected_voice, en
75
  voice_name=selected_voice,
76
  voice_rate=voice_rate,
77
  subtitle_enabled=enable_subtitles,
78
- bgm_type="random" if enable_bgm else "",
79
- n_threads=2
80
- )
81
-
82
- try:
83
- # Bước 1: Khởi tạo
84
- yield None, stream_log("Đang kết nối AI Pipeline...")
85
- time.sleep(0.5) # Tạo khoảng nghỉ nhỏ để UI kịp cập nhật
86
-
87
- if is_vip:
88
- yield None, stream_log("Xác nhận VIP: Ưu tiên xử lý băng thông cao.")
89
-
90
- # Bước 2: Tìm kiếm (Đẩy log TRƯỚC khi gọi engine)
91
- yield None, stream_log(f"Tìm kiếm tài nguyên Pexels cho: {params.video_subject}")
92
-
93
- # GỌI ENGINE CỐT LÕI (Tiến trình nặng)
94
- result = tm.start(task_id=task_id, params=params)
95
-
96
- # Bước 3: Sau khi engine bắt đầu/hoàn tất từng phần, đẩy tiếp log
97
- yield None, stream_log("Đang tổng hợp giọng nói AI và tạo phụ đề...")
98
- yield None, stream_log("FFmpeg: Đang ghép nhạc nền và kết xuất video cuối cùng...")
99
-
100
- if result and "videos" in result and len(result["videos"]) > 0:
101
- video_path = result["videos"][0]
102
- yield video_path, stream_log("HOÀN THÀNH: Video đã sẵn sàng để tải về!", "SUCCESS")
103
- else:
104
- yield None, stream_log("LỖI: Tiến trình kết thúc nhưng không tìm thấy file.", "ERROR")
105
-
106
- except Exception as e:
107
- yield None, stream_log(f"LỖI HỆ THỐNG: {str(e)}", "CRITICAL")
108
-
109
- # --- 4. GIAO DIỆN GRADIO ---
110
- with gr.Blocks(theme=gr.Theme.from_hub("NeoPy/shadowthedgehog"), css=CSS) as demo:
111
- gr.HTML('<div class="main-title">AI VIDEO ENGINE PRO</div>')
112
-
113
- with gr.Row():
114
- with gr.Column(scale=1):
115
- with gr.Group():
116
- gr.Markdown("### ⚙️ Cấu hình Video")
117
- v_key = gr.Textbox(label="🔑 MÃ VIP ACCESS", placeholder="Nhập mã ưu tiên...", type="password", elem_classes="vip-input")
118
- v_script = gr.Textbox(label="KỊCH BẢN VIDEO", placeholder="Nhập nội dung...", lines=8)
119
- with gr.Row():
120
- v_duration = gr.Slider(5, 10, value=5, step=1, label="Độ dài Clip (s)")
121
- v_rate = gr.Slider(0.5, 1.5, value=1.0, step=0.1, label="Tốc độ giọng")
122
- v_voice = gr.Dropdown(get_voice_list(), value="vi-VN-HoaiMyNeural", label="Giọng đọc")
123
- with gr.Row():
124
- v_sub = gr.Checkbox(label="Phụ đề", value=True)
125
- v_bgm = gr.Checkbox(label="Nhạc nền", value=True)
126
-
127
- gen_btn = gr.Button("🚀 BẮT ĐẦU TẠO VIDEO", variant="primary", elem_classes="gen-btn")
128
-
129
- with gr.Group():
130
- gr.Markdown("### 📟 TIẾN TRÌNH HỆ THỐNG")
131
- # lines=2 để khớp với yêu cầu chỉ hiện 2 dòng
132
- console_output = gr.Textbox(label=None, lines=2, elem_classes="console-log", interactive=False)
133
-
134
- with gr.Column(scale=1):
135
- gr.Markdown("### 🎬 KẾT QUẢ")
136
- video_output = gr.Video(label="Video", interactive=False, show_label=False)
137
-
138
- with gr.Group():
139
- gr.Markdown("### 📊 Trạng thái")
140
- gr.Markdown("Phần cứng: **ZeroGPU NVIDIA**\nĐồng bộ: **Real-time Streaming**")
141
-
142
- gr.Markdown("> **Lưu ý:** Log trên sẽ tự động cập nhật theo tiến trình thực tế của hệ thống.")
143
-
144
- gr.HTML('<div class="footer-container"><hr>© 2026 Abu Alone</div>')
145
-
146
- gen_btn.click(
147
- fn=handle_rendering,
148
- inputs=[v_script, v_duration, v_rate, v_voice, v_sub, v_bgm, v_key],
149
- outputs=[video_output, console_output]
150
- )
151
-
152
- if __name__ == "__main__":
153
- demo.queue(max_size=2).launch(server_name="0.0.0.0", server_port=7860)
 
1
  # =========================================================
2
+ # VERSION 2.5.5 - LIVE STREAMING LOGS (AUTO-SCROLL)
3
  # =========================================================
4
 
5
  import os
 
38
  except: pass
39
  return ["vi-VN-HoaiMyNeural", "en-US-AvaNeural"]
40
 
41
+ # --- 2. CSS CUSTOM (FIXED LOG BOX & REMOVED BORDERS) ---
42
  CSS = """
43
  .main-title { font-size: 32px; font-weight: 800; text-align: center; color: #ffffff; margin-bottom: 20px; }
44
  .gen-btn { background-color: #28a745 !important; border: none !important; color: white !important; font-weight: bold !important; height: 50px !important; border-radius: 8px !important; }
45
  .footer-container { text-align: center; color: #666; margin-top: 20px; font-size: 12px; }
46
+ .console-log { font-family: 'Courier New', Courier, monospace !important; font-size: 12px !important; background: #080808 !important; color: #00ff41 !important; border: 1px solid #333 !important; overflow-y: auto !important; }
47
  .vip-input input { border-bottom: 2px solid #ffd700 !important; border-top: none !important; border-left: none !important; border-right: none !important; background: transparent !important; }
48
  .gradio-container { background-color: #0b0f19 !important; }
49
  .gradio-group { border: none !important; box-shadow: none !important; background: transparent !important; }
50
  """
51
 
52
+ # --- 3. CORE RENDERING WITH LIVE LOG STREAMING ---
53
  @spaces.GPU(duration=120)
54
  def handle_rendering(video_script, clip_duration, voice_rate, selected_voice, enable_subtitles, enable_bgm, user_key):
55
  if not video_script:
56
+ raise gr.Error("Script is required!")
57
 
58
  is_vip = (user_key.strip() == VIP_KEY and VIP_KEY != "")
59
  task_id = str(uuid4())
60
+ log_history = []
61
 
62
  def stream_log(msg, level="INFO"):
63
  ts = time.strftime("%H:%M:%S")
64
+ log_entry = f"[{ts}] {level}: {msg}"
65
+ log_history.append(log_entry)
66
+ # Keeps only last 50 lines for performance, but displays in auto-scroll area
67
+ if len(log_history) > 50: log_history.pop(0)
68
+ return "\n".join(log_history)
69
 
70
  params = VideoParams(
71
  video_subject=video_script[:30].strip(),
 
76
  voice_name=selected_voice,
77
  voice_rate=voice_rate,
78
  subtitle_enabled=enable_subtitles,
79
+