File size: 1,690 Bytes
cb7c94c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, redirect, url_for, send_file
import moviepy.editor as mp
import cv2
from gtts import gTTS
import os
import progress
import uuid
import requests
from bs4 import BeautifulSoup

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/dub', methods=['POST'])
def dub():
    # Get the video source from the user
    source = request.form.get('source')
    if source == 'url':
        url = request.form.get('url')
        # Download the video from the URL
        response = requests.get(url)
        file = "video.mp4"
        with open(file, "wb") as f:
            f.write(response.content)
    else:
        file = request.files['file']
        filename = str(uuid.uuid4().hex) + ".mp4"
        file.save(filename)
    
    # Load the video using moviepy
    video = mp.VideoFileClip(file)

    # Create the audio in Hindi using gTTS
    audio = gTTS(video.audio.fps, 'hi')
    audio_filename = str(uuid.uuid4().hex) + ".mp3"
    audio.save(audio_filename)

    # Replace the audio of the video with the Hindi audio
    video.audio = mp.AudioFileClip(audio_filename)

    # Save the dubbed video
    dubbed_filename = str(uuid.uuid4().hex) + ".mp4"
    video.write_videofile(dubbed_filename, progress_bar=progress.bar.IncrementalBar)

    # Delete the temporary audio and video files
    os.remove(file)
    os.remove(audio_filename)

    return redirect(url_for('download', filename=dubbed_filename))

@app.route('/download/<filename>')
def download(filename):
    return send_file(filename, as_attachment=True)

if __name__ == '__main__':
    app.run(host="0.0.0.0",port=7860,debug=True)