muhammadzain commited on
Commit
540103b
1 Parent(s): e486e8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -6
app.py CHANGED
@@ -6,6 +6,8 @@ import cv2
6
  import os
7
  import urllib.request
8
  import moviepy
 
 
9
 
10
  hide_streamlit_style = """
11
  <style>
@@ -16,6 +18,15 @@ hide_streamlit_style = """
16
 
17
  """
18
 
 
 
 
 
 
 
 
 
 
19
  st.set_page_config(layout="wide")
20
 
21
 
@@ -44,12 +55,17 @@ def upscale(file,task,_progressBar = None):
44
  st.success('Done!', icon="✅")
45
  return True
46
  elif file.type.split('/')[0] == 'video':
 
 
 
 
 
47
  cap = cv2.VideoCapture(file.name)
48
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
49
  fps = int(cap.get(cv2.CAP_PROP_FPS))
50
  width = int(cap.get(3))
51
  height = int(cap.get(4))
52
- writer = cv2.VideoWriter("processed_"+file.name,fourcc,fps,(width*int(task),height*int(task)))
53
  length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
54
  step_size = 1.0/length
55
  progress = 0
@@ -65,8 +81,7 @@ def upscale(file,task,_progressBar = None):
65
  print(progress)
66
  progress += step_size
67
  my_bar.progress(progress-0.000000001)
68
- with st.sidebar:
69
- st.success('Done! Thankyou for your patience', icon="✅")
70
  return True
71
  return True
72
 
@@ -109,6 +124,11 @@ def upscale(file,task,_progressBar = None):
109
 
110
  # If file is video
111
  elif file.type.split('/')[0] == 'video':
 
 
 
 
 
112
  cap = cv2.VideoCapture(file.name)
113
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
114
  fps = int(cap.get(cv2.CAP_PROP_FPS))
@@ -117,7 +137,7 @@ def upscale(file,task,_progressBar = None):
117
  if height > 2160 or width > 3840:
118
  with st.sidebar:
119
  st.success("Sorry, I can't processed Video with resolution above 4k. Please select custom size option.!", icon="ℹ️")
120
- writer = cv2.VideoWriter("processed_" + file.name, fourcc, fps, (int(task[0]),int(task[1])))
121
  length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
122
  step_size = 1.0 / length
123
  progress = 0
@@ -131,8 +151,7 @@ def upscale(file,task,_progressBar = None):
131
  writer.write(frame)
132
  progress += step_size
133
  my_bar.progress(progress-0.000000001)
134
- with st.sidebar:
135
- st.success('Done! Thankyou for your patience', icon="✅")
136
  return True
137
  return "It's second"
138
 
@@ -241,6 +260,17 @@ with col2:
241
  print(task)
242
  st.session_state.disable_download = not upscale(file,task,progressBar)
243
 
 
 
 
 
 
 
 
 
 
 
 
244
  #print(resulted_file.shape)
245
 
246
  st.markdown("\n")
 
6
  import os
7
  import urllib.request
8
  import moviepy
9
+ import threading
10
+
11
 
12
  hide_streamlit_style = """
13
  <style>
 
18
 
19
  """
20
 
21
+
22
+ def sound_extract(file):
23
+ video = moviepy.editor.VideoFileClip(file)
24
+ video.audio.write_audiofile(file.split('.')[0] + '.mp3')
25
+
26
+ def remove_file(file):
27
+ os.remove('deep_'+file)
28
+
29
+
30
  st.set_page_config(layout="wide")
31
 
32
 
 
55
  st.success('Done!', icon="✅")
56
  return True
57
  elif file.type.split('/')[0] == 'video':
58
+
59
+ t1 = threading.Thread(target=sound_extract, args=(file.name,))
60
+
61
+ t1.start()
62
+
63
  cap = cv2.VideoCapture(file.name)
64
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
65
  fps = int(cap.get(cv2.CAP_PROP_FPS))
66
  width = int(cap.get(3))
67
  height = int(cap.get(4))
68
+ writer = cv2.VideoWriter("deep_"+file.name,fourcc,fps,(width*int(task),height*int(task)))
69
  length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
70
  step_size = 1.0/length
71
  progress = 0
 
81
  print(progress)
82
  progress += step_size
83
  my_bar.progress(progress-0.000000001)
84
+
 
85
  return True
86
  return True
87
 
 
124
 
125
  # If file is video
126
  elif file.type.split('/')[0] == 'video':
127
+
128
+ t1 = threading.Thread(target=sound_extract, args=(file.name,))
129
+
130
+ t1.start()
131
+
132
  cap = cv2.VideoCapture(file.name)
133
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
134
  fps = int(cap.get(cv2.CAP_PROP_FPS))
 
137
  if height > 2160 or width > 3840:
138
  with st.sidebar:
139
  st.success("Sorry, I can't processed Video with resolution above 4k. Please select custom size option.!", icon="ℹ️")
140
+ writer = cv2.VideoWriter("deep_" + file.name, fourcc, fps, (int(task[0]),int(task[1])))
141
  length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
142
  step_size = 1.0 / length
143
  progress = 0
 
151
  writer.write(frame)
152
  progress += step_size
153
  my_bar.progress(progress-0.000000001)
154
+
 
155
  return True
156
  return "It's second"
157
 
 
260
  print(task)
261
  st.session_state.disable_download = not upscale(file,task,progressBar)
262
 
263
+ if file.type.split('/')[0] == 'video':
264
+ with st.sidebar:
265
+ st.info("Preparing for Download. Please wait.", icon="ℹ️")
266
+ audio = moviepy.editor.AudioFileClip(file.name.split('.')[0] + '.mp3')
267
+ video = moviepy.editor.VideoFileClip("deep_"+file.name)
268
+ videoClip = video.set_audio(audio)
269
+ videoClip.write_videofile('processed_'+file.name)
270
+ t2 = threading.Thread(target=remove_file(file.name))
271
+ t2.start()
272
+ st.success('Done! Thankyou for your patience', icon="✅")
273
+
274
  #print(resulted_file.shape)
275
 
276
  st.markdown("\n")