File size: 3,824 Bytes
acaeeaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="vi" charset="UTF-8">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Video Creator</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
    <div class="container" id="app">
        <header class="bg-gradient">
            <img src="/static/banner.png" alt="Banner" class="img-fluid">
            <nav class="mt-2">
                <a href="/" class="btn btn-primary mx-3">Trang chủ</a>
                <a href="/pexels" class="btn btn-secondary mx-3">Tạo video từ Pexels</a>
                <a href="#" class="btn btn-info mx-3">Hướng dẫn</a>
                <a href="#" class="btn btn-success mx-3">Liên hệ</a>
            </nav>
        </header>
        <main class="my-5">
            <h2 class="text-center mb-4 highlight-text">ỨNG DỤNG SẢN XUẤT VIDEO TỰ ĐỘNG</h2>
            <div class="row">
                <div class="col-md-6">
                    <form id="form1" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="imageFolder">Chọn thư mục ảnh/video:</label>
                            <input type="file" class="form-control-file" id="imageFolder" name="imageFolder" webkitdirectory multiple required>
                        </div>
                        <div class="form-group">
                            <label for="voiceOff">Chọn file voice off:</label>
                            <input type="file" class="form-control-file" id="voiceOff" name="voiceOff" required>
                        </div>
                        <div class="form-group">
                            <label for="backgroundMusic">Chọn file nhạc nền (tùy chọn):</label>
                            <input type="file" class="form-control-file" id="backgroundMusic" name="backgroundMusic">
                        </div>
                        <button type="button" class="btn btn-primary" onclick="createVideoFromPexels()">Tạo video</button>
                    </form>
                </div>
            </div>
        </main>
        <div id="notification"></div>
    </div>

    <script>

        async function createVideoFromPexels() {

            const formData = new FormData(document.getElementById('form1'));

            const response = await fetch('/create-video-from-pexels', {

                method: 'POST',

                body: formData

            });

            const result = await response.json();

            if (result.message) {

                alert(result.message);

            } else {

                alert('Video đã được tạo thành công');

            }

        }



        // Kết nối WebSocket để nhận thông báo

        const socket = new WebSocket('ws://localhost:8000/ws');

        socket.onmessage = function(event) {

            const data = JSON.parse(event.data);

            const notificationDiv = document.getElementById('notification');

            const notificationElement = document.createElement('div');

            notificationElement.classList.add('alert', 'alert-info');

            notificationElement.textContent = `Task ID: ${data.task_id} - ${data.message}`;

            notificationDiv.appendChild(notificationElement);



            // Xóa thông báo sau 5 giây

            setTimeout(() => {

                notificationElement.remove();

            }, 5000);

        };

    </script>
</body>
</html>