Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import os
|
| 3 |
import shutil
|
| 4 |
import gradio as gr
|
|
@@ -17,7 +16,6 @@ def run_automation(prompts, avatar, cookies_file, headless, wait_time, mode):
|
|
| 17 |
|
| 18 |
# 1) Lưu cookies.json nếu user upload
|
| 19 |
if cookies_file is not None:
|
| 20 |
-
# cookies_file.name là đường dẫn tạm tới file upload
|
| 21 |
shutil.copy(cookies_file.name, COOKIES_FILE)
|
| 22 |
|
| 23 |
# 2) Ghi prompt vào input.txt
|
|
@@ -34,7 +32,7 @@ def run_automation(prompts, avatar, cookies_file, headless, wait_time, mode):
|
|
| 34 |
def log_cb(msg):
|
| 35 |
logs.append(msg)
|
| 36 |
|
| 37 |
-
# 4)
|
| 38 |
runner = AutomationRunner(
|
| 39 |
headless=headless,
|
| 40 |
wait_time=wait_time,
|
|
@@ -55,16 +53,47 @@ with gr.Blocks() as demo:
|
|
| 55 |
gr.Markdown("## HaiLuo AI Video Automation")
|
| 56 |
with gr.Row():
|
| 57 |
with gr.Column(scale=2):
|
| 58 |
-
prompts = gr.Textbox(
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
run_btn = gr.Button("🚀 Chạy Automation")
|
| 65 |
with gr.Column(scale=1):
|
| 66 |
-
log_output = gr.Textbox(
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
run_btn.click(
|
| 69 |
run_automation,
|
| 70 |
inputs=[prompts, avatar, cookies_file, headless, wait_time, mode],
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import shutil
|
| 3 |
import gradio as gr
|
|
|
|
| 16 |
|
| 17 |
# 1) Lưu cookies.json nếu user upload
|
| 18 |
if cookies_file is not None:
|
|
|
|
| 19 |
shutil.copy(cookies_file.name, COOKIES_FILE)
|
| 20 |
|
| 21 |
# 2) Ghi prompt vào input.txt
|
|
|
|
| 32 |
def log_cb(msg):
|
| 33 |
logs.append(msg)
|
| 34 |
|
| 35 |
+
# 4) Chạy automation
|
| 36 |
runner = AutomationRunner(
|
| 37 |
headless=headless,
|
| 38 |
wait_time=wait_time,
|
|
|
|
| 53 |
gr.Markdown("## HaiLuo AI Video Automation")
|
| 54 |
with gr.Row():
|
| 55 |
with gr.Column(scale=2):
|
| 56 |
+
prompts = gr.Textbox(
|
| 57 |
+
lines=8,
|
| 58 |
+
label="Nhập các Scene (mỗi dòng `Scene X: ...`)",
|
| 59 |
+
value="Scene 1: "
|
| 60 |
+
)
|
| 61 |
+
avatar = gr.File(
|
| 62 |
+
label="Ảnh nhân vật (tuỳ chọn)",
|
| 63 |
+
file_count="single", # sửa thành "single"
|
| 64 |
+
file_types=["image"] # hoặc cụ thể hơn ["png","jpg","jpeg"]
|
| 65 |
+
)
|
| 66 |
+
cookies_file = gr.File(
|
| 67 |
+
label="Upload cookies.json (bắt buộc lần đầu)",
|
| 68 |
+
file_count="single", # sửa thành "single"
|
| 69 |
+
file_types=[".json"]
|
| 70 |
+
)
|
| 71 |
+
mode = gr.Radio(
|
| 72 |
+
["subject", "text"],
|
| 73 |
+
label="Chế độ",
|
| 74 |
+
value="subject"
|
| 75 |
+
)
|
| 76 |
+
headless = gr.Checkbox(
|
| 77 |
+
label="Chạy headless",
|
| 78 |
+
value=True
|
| 79 |
+
)
|
| 80 |
+
wait_time = gr.Slider(
|
| 81 |
+
60, 1800,
|
| 82 |
+
value=600,
|
| 83 |
+
step=30,
|
| 84 |
+
label="Thời gian chờ (giây)"
|
| 85 |
+
)
|
| 86 |
run_btn = gr.Button("🚀 Chạy Automation")
|
| 87 |
with gr.Column(scale=1):
|
| 88 |
+
log_output = gr.Textbox(
|
| 89 |
+
lines=15,
|
| 90 |
+
label="Logs",
|
| 91 |
+
interactive=False
|
| 92 |
+
)
|
| 93 |
+
video_out = gr.File(
|
| 94 |
+
label="Download Videos",
|
| 95 |
+
file_count="multiple"
|
| 96 |
+
)
|
| 97 |
run_btn.click(
|
| 98 |
run_automation,
|
| 99 |
inputs=[prompts, avatar, cookies_file, headless, wait_time, mode],
|