ZiyuG commited on
Commit
0245186
1 Parent(s): e64d541

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -1,8 +1,7 @@
1
- import spaces
2
  import gradio as gr
3
  from evaluate import eval
4
  from datetime import datetime
5
- import os, shutil
6
  import warnings, tempfile
7
  from audio import gen_audio
8
  warnings.filterwarnings("ignore")
@@ -50,22 +49,19 @@ def evaluate_sign_language(user_video, standard_video_option):
50
  tmp = tempfile.TemporaryDirectory()
51
  tmpdir = tmp.name
52
  new_path = tmpdir + "/user.mp4"
53
- # 将文件从临时路径复制到新路径
54
  shutil.copy(user_video, new_path)
55
  shutil.copy(videos[standard_video_option], tmpdir + "/standard.mp4")
56
- shutil.copy(jsons[standard_video_option], tmpdir + "/standard.json") #comment if produce standard json files
57
- ######
58
  test, standard = user_video, videos[standard_video_option]
59
  score, final_merged_intervals, comments = eval(test, standard, tmpdir)
60
- # return None # comment if NOT produce standard json files
61
 
62
  if score < 95:
63
  score = 0
64
  elif score < 98:
65
- score = 50 * (score - 95) / 3 # 将95到98之间的数映射到0到50
66
  elif 98 <= score <= 100:
67
  score = 50 * (score - 98) / 2 + 50
68
- # 获取当前日期
69
  current_date = datetime.now().strftime("%Y年%m月%d日")
70
 
71
  # 初始化反馈报告
@@ -106,6 +102,7 @@ def evaluate_sign_language(user_video, standard_video_option):
106
 
107
  def cleanup_temp_dir(tmp_dir):
108
  if tmp_dir:
 
109
  print(f"Cleaning up temporary directory: {tmp_dir.name}")
110
  tmp_dir.cleanup()
111
  return "临时目录已清理"
@@ -162,14 +159,11 @@ with gr.Blocks(
162
  evaluate_sign_language,
163
  inputs=[upload_video, video_selector],
164
  outputs=[advice_output, compare_video_player, tmp_dir_state],
165
- # _js="() => new Promise(resolve => setTimeout(resolve, 500))"
166
  )
167
- # time.sleep(0.5)
168
 
169
- # 视频加载后自动清理临时目录
170
  compare_video_player.change(
171
  fn=cleanup_temp_dir,
172
- inputs=tmp_dir_state, # 这里传递的是存储的临时目录状态
173
  outputs=None
174
  )
175
 
 
 
1
  import gradio as gr
2
  from evaluate import eval
3
  from datetime import datetime
4
+ import os, shutil, spaces
5
  import warnings, tempfile
6
  from audio import gen_audio
7
  warnings.filterwarnings("ignore")
 
49
  tmp = tempfile.TemporaryDirectory()
50
  tmpdir = tmp.name
51
  new_path = tmpdir + "/user.mp4"
 
52
  shutil.copy(user_video, new_path)
53
  shutil.copy(videos[standard_video_option], tmpdir + "/standard.mp4")
54
+
 
55
  test, standard = user_video, videos[standard_video_option]
56
  score, final_merged_intervals, comments = eval(test, standard, tmpdir)
 
57
 
58
  if score < 95:
59
  score = 0
60
  elif score < 98:
61
+ score = 50 * (score - 95) / 3
62
  elif 98 <= score <= 100:
63
  score = 50 * (score - 98) / 2 + 50
64
+
65
  current_date = datetime.now().strftime("%Y年%m月%d日")
66
 
67
  # 初始化反馈报告
 
102
 
103
  def cleanup_temp_dir(tmp_dir):
104
  if tmp_dir:
105
+ time.sleep(0.5)
106
  print(f"Cleaning up temporary directory: {tmp_dir.name}")
107
  tmp_dir.cleanup()
108
  return "临时目录已清理"
 
159
  evaluate_sign_language,
160
  inputs=[upload_video, video_selector],
161
  outputs=[advice_output, compare_video_player, tmp_dir_state],
 
162
  )
 
163
 
 
164
  compare_video_player.change(
165
  fn=cleanup_temp_dir,
166
+ inputs=tmp_dir_state,
167
  outputs=None
168
  )
169