File size: 4,564 Bytes
850f5fb
29859a8
66db1de
850f5fb
 
29859a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
850f5fb
 
29859a8
 
 
 
 
 
 
 
 
 
 
 
850f5fb
e27f867
29859a8
 
 
 
 
 
 
 
21d5f5b
29859a8
 
 
850f5fb
 
 
 
9c07a52
a24f45f
850f5fb
 
 
9c07a52
850f5fb
9c07a52
 
 
 
850f5fb
 
 
 
 
f12fcd0
 
 
 
 
 
 
 
 
534a0f8
f12fcd0
 
 
 
 
 
 
 
 
 
 
850f5fb
 
eeb162f
850f5fb
 
 
 
 
534a0f8
850f5fb
 
 
 
cb1cfa4
0001b20
850f5fb
 
293d61c
850f5fb
 
 
 
4471424
850f5fb
4471424
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import gradio as gr
import random
from gradio_client import Client

def create_image(description):
    seed = 3343 + random.randint(0, 100000)
    image_client = Client("https://bytedance-hyper-sdxl-1step-t2i.hf.space/")
    result = image_client.predict(
        num_images=1,
        height=1024,
        width=1024,
        prompt=description,
        seed=seed,
        api_name="/process_image"
    )
    if result:
        image_url = result[0]["image"]
        return image_url
    else:
        return "Error: Could not retrieve image."

def generate_content(description):
    content_client = Client("https://nick088-groq-api-chat.hf.space/")
    unchange_prompt = 'Chỉ viết nội dung và đưa kết quả nội dung, không cần diễn giải kể cả here is...'
    result = content_client.predict(
        message=description + unchange_prompt,
        request="llama3-70b-8192",
        param_3=0.5,
        param_4=4096,
        param_5=0.5,
        param_6=42,
        api_name="/chat"
    )
    return result

def create_video(audio_bytes, image_url):
    video_client = Client("https://fffiloni-dreamtalk.hf.space/")
    audio_filepath = video_client.predict(
        audio_bytes,
        api_name="/load_audio"
    )
    result = video_client.predict(
        audio_filepath,
        image_url,
        "M030_front_neutral_level1_001.mat",  # Chọn một emotional style
        api_name="/infer"
    )
    return result['video']

def main():
    with gr.Blocks() as demo:
        with gr.Row():
            gr.Markdown("# VMC 🇻🇳")
            gr.Image("https://huggingface.co/spaces/TDN-M/VMCBeta/resolve/main/demo/cover.jpeg")

        with gr.Row():
            gr.Markdown("""
            Dự án VMC (Virtual MC) là một ứng dụng đa nền tảng, cho phép người dùng tạo video với MC ảo từ hình ảnh và nội dung tuỳ chọn, sử dụng giọng nói tiếng Việt tự nhiên.
            ## Sử dụng
            1. **Bước Tạo Ảnh:** Nhập mô tả về MC rồi nhấn nút "Tạo Ảnh".
            2. **Bước Xây Dựng Nội Dung:** Nhập mô tả nội dung và nhấn nút "Tạo Nội Dung".
            3. **Bước Phòng Thu:** Tải lên file âm thanh tham chiếu hoặc nhập URL âm thanh tham chiếu và nhấn nút "Tạo Âm Thanh".
            4. **Bước Tạo Video:** Nhấn nút "Tạo Video" để tạo video từ ảnh, nội dung, và âm thanh đã tạo.
            ## Liên hệ
            Nếu bạn có bất kỳ câu hỏi nào, vui lòng liên hệ [dung.ngt1988@gmail.com](mailto:dung.ngt1988@gmail.com).
            """)

        with gr.Row():
            gr.HTML("""
            <style>
                .center-video {
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    margin: 20px 0;
                }
                .center-video video {
                    width: 50%;  /* Giảm kích thước video xuống 50% */
                }
            </style>
            """)
            gr.HTML("""
            <div class="center-video">
                <video controls>
                    <source src="https://huggingface.co/spaces/TDN-M/VMCBeta/resolve/main/demo/demo2.mp4" type="video/mp4">
                    Trình duyệt của bạn không hỗ trợ video.
                </video>
            </div>
            """)

        with gr.Row():
            description = gr.Textbox(label="Nhập mô tả cho ảnh bằng tiếng Anh")
            image_button = gr.Button("Tạo Ảnh")
            image_output = gr.Image()
            image_button.click(fn=create_image, inputs=description, outputs=image_output)

        with gr.Row():
            content_description = gr.Textbox(label="Nhập mô tả nội dung")
            content_button = gr.Button("Tạo Nội Dung")
            content_output = gr.Textbox()
            content_button.click(fn=generate_content, inputs=content_description, outputs=content_output)

        with gr.Row():
            gr.HTML('<iframe src="https://tdn-m-function-vmcbeta.hf.space" height="600"></iframe>')

        with gr.Row():
            audio_output = gr.Audio(label="Tải lên âm thanh tham chiếu", type="filepath")
            video_button = gr.Button("Tạo Video")
            video_output = gr.Video()
            video_button.click(fn=create_video, inputs=[audio_output, image_output], outputs=video_output)

    demo.launch(share=True) 
if __name__ == "__main__":
    main()