admin commited on
Commit
9909b2f
·
1 Parent(s): ff565eb
app.py CHANGED
@@ -25,10 +25,7 @@ ZH2EN = {
25
 
26
 
27
  def _L(zh_txt: str):
28
- if LANG:
29
- return ZH2EN[zh_txt]
30
- else:
31
- return zh_txt
32
 
33
 
34
  if __name__ == "__main__":
 
25
 
26
 
27
  def _L(zh_txt: str):
28
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
29
 
30
 
31
  if __name__ == "__main__":
modules/data.py CHANGED
@@ -20,10 +20,7 @@ ZH2EN = {
20
 
21
 
22
  def _L(zh_txt: str):
23
- if LANG:
24
- return ZH2EN[zh_txt]
25
- else:
26
- return zh_txt
27
 
28
 
29
  def encoder_json(file_path: str):
 
20
 
21
 
22
  def _L(zh_txt: str):
23
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
24
 
25
 
26
  def encoder_json(file_path: str):
modules/exif.py CHANGED
@@ -13,7 +13,7 @@ ZH2EN = {
13
  "导出原格式": "Export original format",
14
  "下载清理 EXIF 后的图片": "Download cleaned picture",
15
  "批量处理": "Batch processor",
16
- "上传包含多图片的 zip 压缩包(确保上传进度至 100% 后再提交)": "Upload pictures zip(Please ensure the zip is completely uploaded before clicking submit)",
17
  "导出原格式": "Export original format",
18
  "下载清理 EXIF 后的多图片压缩包": "Download cleaned pictures",
19
  "EXIF 列表": "EXIF list",
@@ -22,10 +22,7 @@ ZH2EN = {
22
 
23
 
24
  def _L(zh_txt: str):
25
- if LANG:
26
- return ZH2EN[zh_txt]
27
- else:
28
- return zh_txt
29
 
30
 
31
  def get_exif(origin_file_path):
@@ -160,7 +157,7 @@ def clexif():
160
  inputs=[
161
  gr.File(
162
  label=_L(
163
- "上传包含多图片的 zip 压缩包(确保上传进度至 100% 后再提交)"
164
  ),
165
  file_types=[".zip"],
166
  ),
 
13
  "导出原格式": "Export original format",
14
  "下载清理 EXIF 后的图片": "Download cleaned picture",
15
  "批量处理": "Batch processor",
16
+ "上传包含多图片的 zip 压缩包 (确保上传进度至 100% 后再提交)": "Upload pictures zip (please ensure the zip is completely uploaded before clicking submit)",
17
  "导出原格式": "Export original format",
18
  "下载清理 EXIF 后的多图片压缩包": "Download cleaned pictures",
19
  "EXIF 列表": "EXIF list",
 
22
 
23
 
24
  def _L(zh_txt: str):
25
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
26
 
27
 
28
  def get_exif(origin_file_path):
 
157
  inputs=[
158
  gr.File(
159
  label=_L(
160
+ "上传包含多图片的 zip 压缩包 (确保上传进度至 100% 后再提交)"
161
  ),
162
  file_types=[".zip"],
163
  ),
modules/gif.py CHANGED
@@ -6,7 +6,7 @@ from moviepy.editor import VideoFileClip
6
  from utils import clean_dir, TMP_DIR, LANG
7
 
8
  ZH2EN = {
9
- "上传视频(请确保上传完整后再点击提交,若时长大于五秒可先在线裁剪)": "Upload video(Please ensure the video is completely uploaded before clicking submit, you can crop it online to less than 5s)",
10
  "倍速": "Speed",
11
  "状态栏": "Status",
12
  "文件名": "Filename",
@@ -15,10 +15,7 @@ ZH2EN = {
15
 
16
 
17
  def _L(zh_txt: str):
18
- if LANG:
19
- return ZH2EN[zh_txt]
20
- else:
21
- return zh_txt
22
 
23
 
24
  def get_frame_dur(gif: Image):
@@ -28,8 +25,8 @@ def get_frame_dur(gif: Image):
28
  return [frame.info.get("duration", dur) for frame in ImageSequence.Iterator(gif)]
29
 
30
 
31
- def resize_gif(target_width: int, target_height: int, input_path, output_path):
32
- gif = Image.open(input_path)
33
  modified_frames = []
34
  for frame in ImageSequence.Iterator(gif):
35
  resized_frame = frame.resize((target_width, target_height), Image.LANCZOS)
@@ -38,7 +35,7 @@ def resize_gif(target_width: int, target_height: int, input_path, output_path):
38
  frame_durations = get_frame_dur(gif)
39
  # 将修改后的帧作为新的 GIF 保存
40
  modified_frames[0].save(
41
- output_path,
42
  format="GIF",
43
  append_images=modified_frames[1:],
44
  save_all=True,
@@ -46,11 +43,13 @@ def resize_gif(target_width: int, target_height: int, input_path, output_path):
46
  loop=0,
47
  )
48
 
 
 
49
 
50
  # outer func
51
  def infer(video_path: str, speed: float, target_w=640, cache=f"{TMP_DIR}/gif"):
52
  status = "Success"
53
- gif_name = out_gif = None
54
  try:
55
  clean_dir(cache)
56
  with VideoFileClip(video_path, audio_fps=16000) as clip:
@@ -60,16 +59,15 @@ def infer(video_path: str, speed: float, target_w=640, cache=f"{TMP_DIR}/gif"):
60
  clip.speedx(speed).to_gif(f"{cache}/input.gif", fps=12)
61
  w, h = clip.size
62
 
63
- in_gif = f"{cache}/input.gif"
64
- out_gif = f"{cache}/output.gif"
65
  target_h = math.ceil(target_w * h / w)
66
  gif_name = os.path.basename(video_path)
67
- resize_gif(target_w, target_h, in_gif, out_gif)
68
 
69
  except Exception as e:
70
  status = f"{e}"
71
 
72
- return status, gif_name, out_gif
73
 
74
 
75
  def video2gif():
@@ -83,7 +81,7 @@ def video2gif():
83
  inputs=[
84
  gr.Video(
85
  label=_L(
86
- "上传视频(请确保上传完整后再点击提交,若时长大于五秒可先在线裁剪)"
87
  )
88
  ),
89
  gr.Slider(label=_L("倍速"), minimum=0.5, maximum=2.0, step=0.25, value=1.0),
 
6
  from utils import clean_dir, TMP_DIR, LANG
7
 
8
  ZH2EN = {
9
+ "上传视频 (请确保上传完整后再点击提交,若时长大于五秒可先在线裁剪)": "Upload video (please ensure the video is completely uploaded before clicking submit, you can crop it online to less than 5s)",
10
  "倍速": "Speed",
11
  "状态栏": "Status",
12
  "文件名": "Filename",
 
15
 
16
 
17
  def _L(zh_txt: str):
18
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
19
 
20
 
21
  def get_frame_dur(gif: Image):
 
25
  return [frame.info.get("duration", dur) for frame in ImageSequence.Iterator(gif)]
26
 
27
 
28
+ def resize_gif(target_width: int, target_height: int, input_gif, output_gif):
29
+ gif = Image.open(input_gif)
30
  modified_frames = []
31
  for frame in ImageSequence.Iterator(gif):
32
  resized_frame = frame.resize((target_width, target_height), Image.LANCZOS)
 
35
  frame_durations = get_frame_dur(gif)
36
  # 将修改后的帧作为新的 GIF 保存
37
  modified_frames[0].save(
38
+ output_gif,
39
  format="GIF",
40
  append_images=modified_frames[1:],
41
  save_all=True,
 
43
  loop=0,
44
  )
45
 
46
+ return output_gif
47
+
48
 
49
  # outer func
50
  def infer(video_path: str, speed: float, target_w=640, cache=f"{TMP_DIR}/gif"):
51
  status = "Success"
52
+ gif_name = gif_out = None
53
  try:
54
  clean_dir(cache)
55
  with VideoFileClip(video_path, audio_fps=16000) as clip:
 
59
  clip.speedx(speed).to_gif(f"{cache}/input.gif", fps=12)
60
  w, h = clip.size
61
 
62
+ gif_in = f"{cache}/input.gif"
 
63
  target_h = math.ceil(target_w * h / w)
64
  gif_name = os.path.basename(video_path)
65
+ gif_out = resize_gif(target_w, target_h, gif_in, f"{cache}/output.gif")
66
 
67
  except Exception as e:
68
  status = f"{e}"
69
 
70
+ return status, gif_name, gif_out
71
 
72
 
73
  def video2gif():
 
81
  inputs=[
82
  gr.Video(
83
  label=_L(
84
+ "上传视频 (请确保上传完整后再点击提交,若时长大于五秒可先在线裁剪)"
85
  )
86
  ),
87
  gr.Slider(label=_L("倍速"), minimum=0.5, maximum=2.0, step=0.25, value=1.0),
modules/github.py CHANGED
@@ -19,10 +19,7 @@ ZH2EN = {
19
 
20
 
21
  def _L(zh_txt: str):
22
- if LANG:
23
- return ZH2EN[zh_txt]
24
- else:
25
- return zh_txt
26
 
27
 
28
  def create_github_release(owner, repo, token, tag, name, description, files):
 
19
 
20
 
21
  def _L(zh_txt: str):
22
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
23
 
24
 
25
  def create_github_release(owner, repo, token, tag, name, description, files):
modules/qr.py CHANGED
@@ -11,10 +11,7 @@ ZH2EN = {
11
 
12
 
13
  def _L(zh_txt: str):
14
- if LANG:
15
- return ZH2EN[zh_txt]
16
- else:
17
- return zh_txt
18
 
19
 
20
  def infer(img_size: int, input_txt: str):
 
11
 
12
 
13
  def _L(zh_txt: str):
14
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
15
 
16
 
17
  def infer(img_size: int, input_txt: str):
modules/rct.py CHANGED
@@ -6,7 +6,7 @@ from utils import clean_dir, TMP_DIR, LANG
6
 
7
  ZH2EN = {
8
  "输入参与者数量": "Number of participants",
9
- "输入分组比率(格式为用:隔开的数字,生成随机分组数据)": "Grouping ratio(Numbers separated by : to generate randomized controlled trial)",
10
  "状态栏": "Status",
11
  "下载随机分组数据 CSV": "Download data CSV",
12
  "随机分组数据预览": "Data preview",
@@ -14,10 +14,7 @@ ZH2EN = {
14
 
15
 
16
  def _L(zh_txt: str):
17
- if LANG:
18
- return ZH2EN[zh_txt]
19
- else:
20
- return zh_txt
21
 
22
 
23
  def list_to_csv(list_of_dicts: list, filename: str):
@@ -49,15 +46,14 @@ def random_allocate(participants: int, ratio: list, out_csv: str):
49
 
50
  sorted_data = sorted(allocation, key=lambda x: x["id"])
51
  list_to_csv(sorted_data, out_csv)
52
- return pd.DataFrame(sorted_data)
53
 
54
 
55
  # outer func
56
  def infer(participants: float, ratios: str, cache=f"{TMP_DIR}/rct"):
57
  ratio = []
58
- previews = None
59
  status = "Success"
60
- out_csv = f"{cache}/output.csv"
61
  try:
62
  ratio_list = ratios.split(":")
63
  clean_dir(cache)
@@ -66,10 +62,11 @@ def infer(participants: float, ratios: str, cache=f"{TMP_DIR}/rct"):
66
  if current_ratio > 0:
67
  ratio.append(current_ratio)
68
 
69
- previews = random_allocate(int(participants), ratio, out_csv)
 
 
70
 
71
  except Exception as e:
72
- out_csv = None
73
  status = f"{e}"
74
 
75
  return status, out_csv, previews
@@ -81,7 +78,7 @@ def rct_generator():
81
  inputs=[
82
  gr.Number(label=_L("输入参与者数量"), value=10),
83
  gr.Textbox(
84
- label=_L("输入分组比率(格式为用:隔开的数字,生成随机分组数据)"),
85
  value="8:1:1",
86
  ),
87
  ],
 
6
 
7
  ZH2EN = {
8
  "输入参与者数量": "Number of participants",
9
+ "输入分组比率 (格式为用:隔开的数字,生成随机分组数据)": "Grouping ratio (numbers separated by : to generate randomized controlled trial)",
10
  "状态栏": "Status",
11
  "下载随机分组数据 CSV": "Download data CSV",
12
  "随机分组数据预览": "Data preview",
 
14
 
15
 
16
  def _L(zh_txt: str):
17
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
18
 
19
 
20
  def list_to_csv(list_of_dicts: list, filename: str):
 
46
 
47
  sorted_data = sorted(allocation, key=lambda x: x["id"])
48
  list_to_csv(sorted_data, out_csv)
49
+ return out_csv, pd.DataFrame(sorted_data)
50
 
51
 
52
  # outer func
53
  def infer(participants: float, ratios: str, cache=f"{TMP_DIR}/rct"):
54
  ratio = []
 
55
  status = "Success"
56
+ out_csv = previews = None
57
  try:
58
  ratio_list = ratios.split(":")
59
  clean_dir(cache)
 
62
  if current_ratio > 0:
63
  ratio.append(current_ratio)
64
 
65
+ out_csv, previews = random_allocate(
66
+ int(participants), ratio, f"{cache}/output.csv"
67
+ )
68
 
69
  except Exception as e:
 
70
  status = f"{e}"
71
 
72
  return status, out_csv, previews
 
78
  inputs=[
79
  gr.Number(label=_L("输入参与者数量"), value=10),
80
  gr.Textbox(
81
+ label=_L("输入分组比率 (格式为用:隔开的数字,生成随机分组数据)"),
82
  value="8:1:1",
83
  ),
84
  ],
modules/smtp.py CHANGED
@@ -19,10 +19,7 @@ ZH2EN = {
19
 
20
 
21
  def _L(zh_txt: str):
22
- if LANG:
23
- return ZH2EN[zh_txt]
24
- else:
25
- return zh_txt
26
 
27
 
28
  def infer(target, title, content, name, email, password, host, port):
 
19
 
20
 
21
  def _L(zh_txt: str):
22
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
23
 
24
 
25
  def infer(target, title, content, name, email, password, host, port):
modules/trans.py CHANGED
@@ -13,16 +13,12 @@ ZH2EN = {
13
 
14
 
15
  def _L(zh_txt: str):
16
- if LANG:
17
- return ZH2EN[zh_txt]
18
- else:
19
- return zh_txt
20
 
21
 
22
  def infer(source, direction):
23
  status = "Success"
24
  result = None
25
- # WARNING, this token is a test token for new developers, and it should be replaced by your token
26
  payload = {
27
  "source": source,
28
  "trans_type": direction,
 
13
 
14
 
15
  def _L(zh_txt: str):
16
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
17
 
18
 
19
  def infer(source, direction):
20
  status = "Success"
21
  result = None
 
22
  payload = {
23
  "source": source,
24
  "trans_type": direction,
modules/url.py CHANGED
@@ -14,10 +14,7 @@ ZH2EN = {
14
 
15
 
16
  def _L(zh_txt: str):
17
- if LANG:
18
- return ZH2EN[zh_txt]
19
- else:
20
- return zh_txt
21
 
22
 
23
  def noxlink(longUrl: str, domain="https://noxlink.net"):
 
14
 
15
 
16
  def _L(zh_txt: str):
17
+ return ZH2EN[zh_txt] if LANG else zh_txt
 
 
 
18
 
19
 
20
  def noxlink(longUrl: str, domain="https://noxlink.net"):
requirements.txt CHANGED
@@ -1,5 +1,2 @@
1
- tqdm
2
- Pillow
3
  exifread
4
- requests
5
  moviepy==1.0.3
 
 
 
1
  exifread
 
2
  moviepy==1.0.3