Spaces:
Runtime error
Runtime error
File size: 7,701 Bytes
7f2690b |
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 |
import os
import datetime
import sys
import shutil
import glob
import argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--path', type=str)
parser.add_argument('--imgsize', type=int, default=100)
parser.add_argument('--num', type=int, default=10000)
args = parser.parse_args()
return args
# -------------------------------------- joint ----------------------------------- #
def create_audio_visual_sec(args, f, name):
dir_list = [name for name in os.listdir(
args.path) if os.path.isdir(os.path.join(args.path, name))]
dir_list.sort()
f.write('''<div align = "center">''')
joint_sec = """
<h3>{}</h3>
<table>
<tbody>
<tr>
<th>Index #</th>
""".format(name)
for name in dir_list:
joint_sec += '''\n<th>{}</th>'''.format(name)
joint_sec += '''\n</tr>\n'''
f.write(joint_sec)
item_list = []
count = []
for i in range(len(dir_list)):
file_list = os.listdir(os.path.join(args.path, dir_list[i]))
file_list.sort()
count.append(len(file_list))
item_list.append(file_list)
file_count = min(count)
for j in range(min(file_count, args.num)):
f.write('''<tr>\n''')
for i in range(-1, len(dir_list)):
if i == -1:
f.write('''<td> sample #{} </td>'''.format(str(j)))
f.write('\n')
else:
sample = os.path.join(dir_list[i], item_list[i][j])
if sample.split('.')[-1] in ['wav', 'mp3']:
f.write(''' <td> <div align = "center"><audio controls=""><source src='{}' type="audio/{}"></audio></div> </td>'''.format(
sample, sample.split('.')[-1]))
elif sample.split('.')[-1] in ['jpg', 'png', 'gif']:
f.write(
''' <td> <div align = "center"><img src='{}' style="zoom:{}%" /></div> </td>'''.format(sample, args.imgsize))
elif sample.split('.')[-1] in ['mp4', 'avi', 'webm']:
f.write(''' <td> <div align = "center"><video id='{}' controls height='400'><source src="{}" type="video/{}" preload = "none"></video> <p>Speed: <input type="text" size="5" value="1" oninput="document.getElementById('{}').playbackRate = parseFloat(event.target.value);"></p></div> </td>'''.format(
sample, sample, sample.split('.')[-1], sample))
f.write('\n')
# <video id='{}' controls><source src="{}" type="video/{}"></video>
f.write('''</tr>\n''')
f.write('''</tbody></table>\n''')
f.write('''</div>\n''')
# -------------------------------------- Audio ----------------------------------- #
def create_audio_sec(args, f, name):
f.write('''<div align = "center">''')
audio_sec = """
<h3>{}</h3>
<table>
<tbody>
<tr>
<th>Index #</th>
<th>Mixture</th>
<th>Original audio #1</th>
<th>Original audio #2</th>
<th>Separated audio #1</th>
<th>Separated audio #2</th>
<th>regenerated audio mix</th>
<th>regenerated audio #1</th>
<th>regenerated audio #2</th>
</tr>\n
""".format(name)
f.write(audio_sec)
folder_path = os.path.join(args.path, 'audio')
dir_list = os.listdir(folder_path)
dir_list.sort()
audio_list = []
for i in range(len(dir_list)):
l = os.listdir(os.path.join(folder_path, dir_list[i]))
l.sort()
audio_list.append(l)
for j in range(len(audio_list[0])):
f.write('''<tr>\n''')
for i in range(-1, len(dir_list)):
if i == -1:
f.write('''<td> audio #{} </td>'''.format(str(j)))
f.write('\n')
else:
audio_path = os.path.join(
folder_path, dir_list[i], audio_list[i][j])
f.write(''' <td> <audio controls=""><source src='{}' type="audio/{}"></audio> </td>'''.format(
audio_path, audio_path.split('.')[-1]))
f.write('\n')
f.write('''</tr>\n''')
f.write('''</tbody></table>\n''')
f.write('''</div>\n''')
# -------------------------------------- Image ----------------------------------- #
def create_image_sec(args, f, name):
f.write('''<div align = "center">''')
image_sec = """
<h3>{}</h3>
<table>
<tbody>
<tr>
<th>Index #</th>
<th>Mixture Spec </th>
<th>Original Spec #1</th>
<th>Original Spec #2</th>
<th>Separated Spec #1</th>
<th>Separated Spec #2</th>
</tr>\n
""".format(name)
f.write(image_sec)
folder_path = os.path.join(args.path, 'spec_img')
dir_list = os.listdir(folder_path)
dir_list.sort()
image_list = []
for i in range(len(dir_list)):
l = os.listdir(os.path.join(folder_path, dir_list[i]))
l.sort()
image_list.append(l)
for j in range(len(image_list[0])):
f.write('''<tr>\n''')
for i in range(-1, len(dir_list)):
if i == -1:
f.write('''<td> audio #{} </td>'''.format(str(j)))
f.write('\n')
else:
img_path = os.path.join(
folder_path, dir_list[i], image_list[i][j])
f.write(''' <td> <div align = "center"><img src='{}' style="zoom:{}%" /></div> </td>'''.format(
img_path, 175))
f.write('\n')
f.write('''</tr>\n''')
f.write('''</tbody></table>\n''')
f.write('''</div>\n''')
# -------------------------------------- Video ----------------------------------- #
def create_video_sec(args, f, name):
f.write('''<div align = "center">''')
video_sec = """
<h3>{}</h3>
<table>
<tbody>
<tr>
<th></th>
<th></th>
<th></th>
</tr>\n
""".format(name)
f.write(video_sec)
# folder_path = os.path.join(args.path, 'videos')
video_list = glob.glob('%s/*.mp4' % args.path)
video_list.sort()
columns = 3
rows = len(video_list) // columns + 1
for i in range(rows):
f.write('''<tr>\n''')
for j in range(columns):
index = i * columns + j
if index < len(video_list):
video_path = video_list[i * columns + j]
f.write(''' <td> <div align = "center"><h4>{}</h4><video width="480" onmouseover = "this.controls = true;" onmouseout = "this.controls = false;"><source src="{}" type="video/{}"></video></div> </td>'''.format(
video_path.split('/')[-1], video_path, video_path.split('.')[-1]))
f.write('\n')
f.write('''</tr>\n''')
f.write('''</tbody></table>\n''')
f.write('''</div>\n''')
def webify(args):
html_file = os.path.join(args.path, 'index.html')
f = open(html_file, 'wt')
# head
# <link rel="stylesheet" type="text/css" title="Cool stylesheet" href="style.css">
head = """<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Listening and Looking - UM Owens Lab</title>
</head>
"""
f.write(head)
intro_sec = '''
<body data-gr-c-s-loaded="true">
<h1> Listening and Looking - UM Owens Lab </h1>
<h5> Creator: Ziyang Chen <br>
University of Michigan </h5>
<p> This page contains the results of experiment.</p>
'''
f.write(intro_sec)
# create_audio_sec(args, f, "Audio Separation")
# create_image_sec(args, f, 'Spectorgram Visualization')
# create_video_sec(args, f, 'CAM Visualization')
create_audio_visual_sec(args, f, 'Stereo CRW')
f.write('''</body>\n''')
f.write('''</html>\n''')
f.close()
if __name__ == "__main__":
args = parse_args()
webify(args)
print('Webify Succeed!')
|