akthangdz commited on
Commit
dcc3501
·
1 Parent(s): 39cdb82
Files changed (3) hide show
  1. app.py +22 -64
  2. requirements.txt +4 -4
  3. ttv.py +24 -19
app.py CHANGED
@@ -1,76 +1,34 @@
1
  import gradio as gr
2
- import os
3
  import subprocess
4
- from ttv import generate_video # We'll modify ttv.py to make it a function
5
 
6
- def install_dependencies():
7
  try:
8
- # Cài đặt diffusers từ git
9
- subprocess.run(["pip", "install", "-U", "git+https://github.com/huggingface/diffusers"],
10
- check=True,
11
- capture_output=True)
12
 
13
- # Cài đặt inference-script
14
- subprocess.run(["pip", "install", "-e", ".[inference-script]"],
15
- check=True,
16
- capture_output=True)
17
-
18
- return "✅ Đã cài đặt thành công các gói phụ thuộc!"
19
- except subprocess.CalledProcessError as e:
20
- return f"❌ Lỗi khi cài đặt: {str(e)}"
21
-
22
- def text_to_video(prompt, negative_prompt):
23
- # Generate video from text
24
- output_path = generate_video(prompt, negative_prompt)
25
- return output_path
26
 
27
- def list_videos():
28
- # List all MP4 files in the current directory
29
- videos = [f for f in os.listdir('.') if f.endswith('.mp4')]
30
- return videos
31
-
32
- # Create Gradio interface
33
  with gr.Blocks() as demo:
34
- gr.Markdown("# Chuyển Văn Bản Thành Video")
35
-
36
- # Add installation button at the top
37
- install_btn = gr.Button("Cài đặt Dependencies")
38
- install_output = gr.Textbox(label="Trạng thái cài đặt", interactive=False)
39
 
40
  with gr.Row():
41
- with gr.Column():
42
- # Input components
43
- text_input = gr.Textbox(label="Nhập nội dung video", lines=3)
44
- neg_prompt = gr.Textbox(label="Từ khóa loại trừ",
45
- value="chất lượng kém, chuyển động không đồng nhất, mờ, giật, biến dạng")
46
- generate_btn = gr.Button("Tạo Video")
47
-
48
- with gr.Column():
49
- # Output video display
50
- video_output = gr.Video(label="Video đã tạo")
51
-
52
- # Gallery of existing videos
53
- gr.Markdown("### Video đã tạo trước đó")
54
- gallery = gr.Gallery(
55
- value=list_videos(),
56
- label="Video có sẵn",
57
- show_label=True,
58
- elem_id="gallery",
59
- columns=2
60
- )
61
 
62
- # Connect components
63
- generate_btn.click(
64
- fn=text_to_video,
65
- inputs=[text_input, neg_prompt],
66
- outputs=[video_output]
67
- )
68
 
69
- # Connect install button
70
- install_btn.click(
71
- fn=install_dependencies,
72
- inputs=[],
73
- outputs=[install_output]
74
- )
75
 
76
- demo.launch()
 
 
 
1
  import gradio as gr
 
2
  import subprocess
3
+ import os
4
 
5
+ def run_ttv():
6
  try:
7
+ result = subprocess.run(['python', 'ttv.py'], capture_output=True, text=True)
 
 
 
8
 
9
+ # Lấy danh sách file mp3 trong thư mục temp
10
+ mp3_files = [f for f in os.listdir('temp') if f.endswith('.mp3')]
11
+ if mp3_files:
12
+ # Trả về đường dẫn đến file mp3 mới nhất
13
+ latest_mp3 = os.path.join('temp', mp3_files[-1])
14
+ return result.stdout, latest_mp3
15
+ return result.stdout, None
16
+ except Exception as e:
17
+ return f"Có lỗi xảy ra: {str(e)}", None
 
 
 
 
18
 
19
+ # Tạo giao diện
 
 
 
 
 
20
  with gr.Blocks() as demo:
21
+ gr.Markdown("# Ứng dụng Text-to-Voice")
 
 
 
 
22
 
23
  with gr.Row():
24
+ run_button = gr.Button("Chạy Text-to-Voice")
25
+ output = gr.Textbox(label="Kết quả")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ # Thêm audio player
28
+ audio_output = gr.Audio(label="File âm thanh đã tạo")
 
 
 
 
29
 
30
+ run_button.click(fn=run_ttv, outputs=[output, audio_output])
 
 
 
 
 
31
 
32
+ # Chạy ứng dụng
33
+ if __name__ == "__main__":
34
+ demo.launch()
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- diffusers
2
- torch
3
- transformers
4
- numpy
 
1
+ diffusers>=0.30.3
2
+ transformers>=0.44.2
3
+ accelerate>=0.34.0
4
+ imageio-ffmpeg>=0.5.1
ttv.py CHANGED
@@ -1,21 +1,26 @@
1
  import torch
2
- from diffusers import LTXPipeline
3
- from diffusers.utils import export_to_video
4
- import os
5
 
6
- def generate_video(prompt, negative_prompt):
7
- pipe = LTXPipeline.from_pretrained("Lightricks/LTX-Video", torch_dtype=torch.bfloat16)
8
- pipe.to("cuda")
9
-
10
- video = pipe(
11
- prompt=prompt,
12
- negative_prompt=negative_prompt,
13
- width=704,
14
- height=480,
15
- num_frames=161,
16
- num_inference_steps=50,
17
- ).frames[0]
18
-
19
- output_path = f"output_{len(os.listdir('.'))}.mp4"
20
- export_to_video(video, output_path, fps=24)
21
- return output_path
 
 
 
 
 
 
 
1
  import torch
2
+ from diffusers import CogVideoXImageToVideoPipeline
3
+ from diffusers.utils import export_to_video, load_image
 
4
 
5
+ prompt = "A little girl is riding a bicycle at high speed. Focused, detailed, realistic."
6
+ image = load_image(image="input.jpg")
7
+ pipe = CogVideoXImageToVideoPipeline.from_pretrained(
8
+ "THUDM/CogVideoX-5b-I2V",
9
+ torch_dtype=torch.bfloat16
10
+ )
11
+
12
+ pipe.enable_sequential_cpu_offload()
13
+ pipe.vae.enable_tiling()
14
+ pipe.vae.enable_slicing()
15
+
16
+ video = pipe(
17
+ prompt=prompt,
18
+ image=image,
19
+ num_videos_per_prompt=1,
20
+ num_inference_steps=50,
21
+ num_frames=49,
22
+ guidance_scale=6,
23
+ generator=torch.Generator(device="cuda").manual_seed(42),
24
+ ).frames[0]
25
+
26
+ export_to_video(video, "temp/output.mp4", fps=8)