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(""" """) gr.HTML("""
""") 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('') 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()