Riz0030 commited on
Commit
1da030a
·
verified ·
1 Parent(s): 2a5953c

Update deepmosaic.py

Browse files
Files changed (1) hide show
  1. deepmosaic.py +39 -85
deepmosaic.py CHANGED
@@ -1,99 +1,53 @@
1
  import os
2
  import sys
3
  import traceback
 
 
 
 
4
  try:
5
- from cores import Options,add,clean,style
6
  from util import util
7
  from models import loadmodel
8
  except Exception as e:
9
- print(e)
10
- input('Please press any key to exit.\n')
11
- sys.exit(0)
12
 
13
- opt = Options().getparse(test_flag = True)
14
  if not os.path.isdir(opt.temp_dir):
15
  util.file_init(opt)
16
 
17
- def main():
 
 
 
 
 
 
 
18
 
19
- if os.path.isdir(opt.media_path):
20
- files = util.Traversal(opt.media_path)
21
- else:
22
- files = [opt.media_path]
23
- if opt.mode == 'add':
24
- netS = loadmodel.bisenet(opt,'roi')
25
- for file in files:
26
- opt.media_path = file
27
- if util.is_img(file):
28
- add.addmosaic_img(opt,netS)
29
- elif util.is_video(file):
30
- add.addmosaic_video(opt,netS)
31
- util.clean_tempfiles(opt, tmp_init = False)
32
- else:
33
- print('This type of file is not supported')
34
- util.clean_tempfiles(opt, tmp_init = False)
35
-
36
- elif opt.mode == 'clean':
37
- netM = loadmodel.bisenet(opt,'mosaic')
38
- if opt.traditional:
39
- netG = None
40
- elif opt.netG == 'video':
41
- netG = loadmodel.video(opt)
42
- else:
43
- netG = loadmodel.pix2pix(opt)
44
-
45
- for file in files:
46
- opt.media_path = file
47
- if util.is_img(file):
48
- clean.cleanmosaic_img(opt,netG,netM)
49
- elif util.is_video(file):
50
- if opt.netG == 'video' and not opt.traditional:
51
- clean.cleanmosaic_video_fusion(opt,netG,netM)
52
- else:
53
- clean.cleanmosaic_video_byframe(opt,netG,netM)
54
- util.clean_tempfiles(opt, tmp_init = False)
55
- else:
56
- print('This type of file is not supported')
57
-
58
- elif opt.mode == 'style':
59
- netG = loadmodel.style(opt)
60
- for file in files:
61
- opt.media_path = file
62
- if util.is_img(file):
63
- style.styletransfer_img(opt,netG)
64
- elif util.is_video(file):
65
- style.styletransfer_video(opt,netG)
66
- util.clean_tempfiles(opt, tmp_init = False)
67
- else:
68
- print('This type of file is not supported')
69
-
70
- util.clean_tempfiles(opt, tmp_init = False)
71
-
72
- if __name__ == '__main__':
73
- if opt.debug:
74
- main()
75
- sys.exit(0)
76
  try:
77
- main()
78
- print('Finished!')
79
- except Exception as ex:
80
- print('--------------------ERROR--------------------')
81
- print('--------------Environment--------------')
82
- print('DeepMosaics: 0.5.1')
83
- print('Python:',sys.version)
84
- import torch
85
- print('Pytorch:',torch.__version__)
86
- import cv2
87
- print('OpenCV:',cv2.__version__)
88
- import platform
89
- print('Platform:',platform.platform())
90
 
91
- print('--------------BUG--------------')
92
- ex_type, ex_val, ex_stack = sys.exc_info()
93
- print('Error Type:',ex_type)
94
- print(ex_val)
95
- for stack in traceback.extract_tb(ex_stack):
96
- print(stack)
97
- input('Please press any key to exit.\n')
98
- #util.clean_tempfiles(tmp_init = False)
99
- sys.exit(0)
 
 
 
 
 
 
 
1
  import os
2
  import sys
3
  import traceback
4
+ import streamlit as st
5
+ import tempfile
6
+ import subprocess
7
+
8
  try:
9
+ from cores import Options, add, clean, style
10
  from util import util
11
  from models import loadmodel
12
  except Exception as e:
13
+ st.error(f"Error loading dependencies: {e}")
14
+ sys.exit(1)
 
15
 
16
+ opt = Options().getparse(test_flag=True)
17
  if not os.path.isdir(opt.temp_dir):
18
  util.file_init(opt)
19
 
20
+ def process_video(input_video):
21
+ """ Memproses video untuk menghapus mosaik. """
22
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
23
+ temp_file.write(input_video.read())
24
+ temp_path = temp_file.name
25
+
26
+ output_path = temp_path.replace(".mp4", "_output.mp4")
27
+ command = ["python3", "deepmosaic.py", "--mode", "clean", "--input", temp_path, "--output", output_path]
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  try:
30
+ subprocess.run(command, check=True)
31
+ return output_path
32
+ except subprocess.CalledProcessError as e:
33
+ st.error(f"Error processing video: {e}")
34
+ return None
35
+
36
+ st.title("🎥 DeepMosaics - Remove Video Mosaic")
37
+ uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "avi", "mov"])
 
 
 
 
 
38
 
39
+ if uploaded_file is not None:
40
+ st.video(uploaded_file)
41
+
42
+ if st.button("Remove Mosaic"):
43
+ with st.spinner("Processing video, please wait..."):
44
+ result_path = process_video(uploaded_file)
45
+
46
+ if result_path:
47
+ st.success("Processing complete!")
48
+ st.video(result_path)
49
+
50
+ with open(result_path, "rb") as file:
51
+ st.download_button("Download Processed Video", file, "output_video.mp4")
52
+ else:
53
+ st.error("Failed to process video. Please try again.")