imseldrith commited on
Commit
cb7c94c
·
1 Parent(s): a3e4b35

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, redirect, url_for, send_file
2
+ import moviepy.editor as mp
3
+ import cv2
4
+ from gtts import gTTS
5
+ import os
6
+ import progress
7
+ import uuid
8
+ import requests
9
+ from bs4 import BeautifulSoup
10
+
11
+ app = Flask(__name__)
12
+
13
+ @app.route('/')
14
+ def index():
15
+ return render_template('index.html')
16
+
17
+ @app.route('/dub', methods=['POST'])
18
+ def dub():
19
+ # Get the video source from the user
20
+ source = request.form.get('source')
21
+ if source == 'url':
22
+ url = request.form.get('url')
23
+ # Download the video from the URL
24
+ response = requests.get(url)
25
+ file = "video.mp4"
26
+ with open(file, "wb") as f:
27
+ f.write(response.content)
28
+ else:
29
+ file = request.files['file']
30
+ filename = str(uuid.uuid4().hex) + ".mp4"
31
+ file.save(filename)
32
+
33
+ # Load the video using moviepy
34
+ video = mp.VideoFileClip(file)
35
+
36
+ # Create the audio in Hindi using gTTS
37
+ audio = gTTS(video.audio.fps, 'hi')
38
+ audio_filename = str(uuid.uuid4().hex) + ".mp3"
39
+ audio.save(audio_filename)
40
+
41
+ # Replace the audio of the video with the Hindi audio
42
+ video.audio = mp.AudioFileClip(audio_filename)
43
+
44
+ # Save the dubbed video
45
+ dubbed_filename = str(uuid.uuid4().hex) + ".mp4"
46
+ video.write_videofile(dubbed_filename, progress_bar=progress.bar.IncrementalBar)
47
+
48
+ # Delete the temporary audio and video files
49
+ os.remove(file)
50
+ os.remove(audio_filename)
51
+
52
+ return redirect(url_for('download', filename=dubbed_filename))
53
+
54
+ @app.route('/download/<filename>')
55
+ def download(filename):
56
+ return send_file(filename, as_attachment=True)
57
+
58
+ if __name__ == '__main__':
59
+ app.run(host="0.0.0.0",port=7860,debug=True)