File size: 10,157 Bytes
c51a38f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
{% extends "base.html" %}

{% block title %}Wav2Lip Inference App{% endblock %}

{% block head_extra %}
    <style>

        .flash-messages {

            list-style: none;

            padding: 0;

            margin: 20px 0;

            text-align: center;

        }

        .flash-messages li {

            padding: 10px 20px;

            margin-bottom: 10px;

            border-radius: 8px;

            font-weight: 600;

            display: inline-block;

            box-shadow: 0 2px 5px rgba(0,0,0,0.1);

            animation: fadeInOut 0.5s ease forwards;

        }

        .flash-messages .error {

            background-color: #dc3545;

            color: #fff;

        }

        .flash-messages .success {

            background-color: #28a745;

            color: #fff;

        }

        .flash-messages .info {

            background-color: #007bff;

            color: #fff;

        }



        /* Form specific styles */

        .inference-form {

            background-color: var(--card-background);

            padding: 40px;

            border-radius: 12px;

            box-shadow: 0 8px 20px var(--shadow);

            margin-top: 40px;

            margin-bottom: 40px;

            animation: fadeInScale 0.8s ease-out forwards;

        }



        .inference-form h2 {

            text-align: center;

            color: var(--primary-color);

            margin-bottom: 30px;

            font-size: 2.2em;

        }



        .form-group {

            margin-bottom: 25px;

        }



        .form-group label {

            display: block;

            margin-bottom: 10px;

            font-weight: 600;

            color: var(--text-color);

            font-size: 1.1em;

        }



        .form-group input[type="file"],

        .form-group select,

        .form-group input[type="number"] {

            width: 100%;

            padding: 12px;

            border: 1px solid var(--border-color);

            border-radius: 8px;

            background-color: var(--background-color);

            color: var(--text-color);

            font-size: 1em;

            box-sizing: border-box; /* Include padding in width */

            transition: border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.2s ease;

        }



        .form-group input[type="file"]:focus,

        .form-group select:focus,

        .form-group input[type="number"]:focus {

            border-color: var(--primary-color);

            box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);

            outline: none;

        }



        .form-group select {

            appearance: none; /* Remove default arrow */

            -webkit-appearance: none;

            -moz-appearance: none;

            background-image: url('data:image/svg+xml;utf8,<svg fill="%23{{ "e0e0e0" if theme == "dark" else "333" }}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 10l5 5 5-5z"/></svg>');

            background-repeat: no-repeat;

            background-position: right 12px top 50%;

            background-size: 16px;

        }



        .checkbox-group {

            display: flex;

            align-items: center;

            margin-bottom: 15px;

            color: var(--text-color);

        }



        .checkbox-group input[type="checkbox"] {

            margin-right: 10px;

            width: 20px;

            height: 20px;

            accent-color: var(--primary-color); /* Changes checkbox color */

        }



        .checkbox-group label {

            margin-bottom: 0; /* Override default label margin */

            font-size: 1em;

        }



        .submit-button {

            width: 100%;

            padding: 15px;

            background-color: var(--primary-color);

            color: #fff;

            border: none;

            border-radius: 8px;

            font-size: 1.2em;

            font-weight: 700;

            cursor: pointer;

            transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;

            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);

        }



        .submit-button:hover {

            background-color: var(--accent-color);

            transform: translateY(-2px);

            box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);

        }



        .submit-button:active {

            transform: translateY(0);

            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);

        }



        /* Animation for flash messages */

        @keyframes fadeInOut {

            0% { opacity: 0; transform: translateY(-10px); }

            100% { opacity: 1; transform: translateY(0); }

        }



        /* Optional: Add a spinner for loading state */

        .loading-overlay {

            position: fixed;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            background-color: rgba(0, 0, 0, 0.7);

            display: flex;

            justify-content: center;

            align-items: center;

            z-index: 9999;

            flex-direction: column;

            color: white;

            font-size: 1.5em;

            display: none; /* Hidden by default */

        }



        .spinner {

            border: 8px solid #f3f3f3; /* Light grey */

            border-top: 8px solid var(--primary-color); /* Blue */

            border-radius: 50%;

            width: 60px;

            height: 60px;

            animation: spin 1s linear infinite;

            margin-bottom: 20px;

        }



        @keyframes spin {

            0% { transform: rotate(0deg); }

            100% { transform: rotate(360deg); }

        }

    </style>
{% endblock %}

{% block content %}
    <ul class="flash-messages">
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <li class="{{ category }}">{{ message }}</li>
                {% endfor %}
            {% endif %}
        {% endwith %}
    </ul>

    <section class="inference-form">
        <h2>Generate Lip-Synced Video</h2>
        <form action="{{ url_for('infer') }}" method="post" enctype="multipart/form-data" id="inferenceForm">
            <div class="form-group">
                <label for="face_file">Select Face Input (Video/Image):</label>
                <input type="file" id="face_file" name="face_file" accept="video/*,image/*" required>
            </div>

            <div class="form-group">
                <label for="audio_file">Select Audio Input (Audio/Video):</label>
                <input type="file" id="audio_file" name="audio_file" accept="audio/*,video/*" required>
            </div>

            <div class="form-group">
                <label for="model_select">Select Wav2Lip Model:</label>
                <select id="model_select" name="model_select" required>
                    <option value="">-- Choose a model --</option>
                    {% for model in models %}
                        <option value="{{ model }}">{{ model }}</option>
                    {% endfor %}
                </select>
            </div>

            <h3>Advanced Options (Optional)</h3>
            <div class="checkbox-group">
                <input type="checkbox" id="static_input" name="static_input">
                <label for="static_input">Use static image (only first frame of video)</label>
            </div>

            <div class="form-group">
                <label for="fps">FPS (for static image input):</label>
                <input type="number" id="fps" name="fps" value="25" min="1" max="60">
            </div>

            <div class="form-group">
                <label for="resize_factor">Resize Factor:</label>
                <input type="number" id="resize_factor" name="resize_factor" value="1" min="1" max="4">
                <small style="color: var(--text-color);">Reduces resolution (e.g., 2 for half resolution). Can improve performance.</small>
            </div>

            <div class="checkbox-group">
                <input type="checkbox" id="rotate" name="rotate">
                <label for="rotate">Rotate 90 degrees clockwise</label>
            </div>

            <div class="checkbox-group">
                <input type="checkbox" id="nosmooth" name="nosmooth">
                <label for="nosmooth">Disable face detection smoothing</label>
            </div>

            <button type="submit" class="submit-button pulse">Generate Lip-Sync</button>
        </form>
    </section>

    <div class="loading-overlay" id="loadingOverlay">
        <div class="spinner"></div>
        <p>Processing your video, please wait...</p>
        <p>This may take several minutes depending on video length and selected options.</p>
    </div>

{% endblock %}

{% block scripts_extra %}
<script>

    document.addEventListener('DOMContentLoaded', function() {

        const inferenceForm = document.getElementById('inferenceForm');

        const loadingOverlay = document.getElementById('loadingOverlay');



        inferenceForm.addEventListener('submit', function() {

            loadingOverlay.style.display = 'flex'; // Show loading overlay on form submission

            // Disable submit button to prevent multiple submissions

            const submitButton = inferenceForm.querySelector('.submit-button');

            if (submitButton) {

                submitButton.disabled = true;

                submitButton.textContent = 'Processing...';

            }

        });



        // Hide loading overlay if page loads without form submission (e.g., on error redirect)

        window.addEventListener('load', function() {

            loadingOverlay.style.display = 'none';

            const submitButton = inferenceForm.querySelector('.submit-button');

            if (submitButton) {

                submitButton.disabled = false;

                submitButton.textContent = 'Generate Lip-Sync';

            }

        });

    });

</script>
{% endblock %}