ash-171 commited on
Commit
14a17dc
·
verified ·
1 Parent(s): ffd2caa

Update src/tools/accent_tool.py

Browse files
Files changed (1) hide show
  1. src/tools/accent_tool.py +15 -5
src/tools/accent_tool.py CHANGED
@@ -6,6 +6,17 @@ from pydub import AudioSegment
6
  import whisper
7
  from speechbrain.pretrained.interfaces import foreign_class
8
 
 
 
 
 
 
 
 
 
 
 
 
9
  class AccentAnalyzerTool:
10
  def __init__(self):
11
  self.whisper_model = whisper.load_model("medium")
@@ -23,10 +34,10 @@ class AccentAnalyzerTool:
23
  try:
24
  self.log("Downloading video...")
25
  tmp_dir = "tmp"
26
- # Clean up tmp folder if exists
27
- if os.path.exists(tmp_dir):
28
- shutil.rmtree(tmp_dir)
29
- os.makedirs(tmp_dir, exist_ok=True)
30
 
31
  video_path = os.path.join(tmp_dir, "video.mp4")
32
 
@@ -70,7 +81,6 @@ class AccentAnalyzerTool:
70
  f"**Transcript of the audio:**\n\n *{transcript.strip(' ')}*"
71
  )
72
 
73
- shutil.rmtree(tmp_dir, ignore_errors=True)
74
  return summary
75
 
76
  except Exception as e:
 
6
  import whisper
7
  from speechbrain.pretrained.interfaces import foreign_class
8
 
9
+ def clear_tmp_dir(path):
10
+ for filename in os.listdir(path):
11
+ file_path = os.path.join(path, filename)
12
+ try:
13
+ if os.path.isfile(file_path) or os.path.islink(file_path):
14
+ os.unlink(file_path)
15
+ elif os.path.isdir(file_path):
16
+ shutil.rmtree(file_path)
17
+ except Exception as e:
18
+ print(f'Failed to delete {file_path}. Reason: {e}')
19
+
20
  class AccentAnalyzerTool:
21
  def __init__(self):
22
  self.whisper_model = whisper.load_model("medium")
 
34
  try:
35
  self.log("Downloading video...")
36
  tmp_dir = "tmp"
37
+ if not os.path.exists(tmp_dir):
38
+ os.makedirs(tmp_dir, exist_ok=True)
39
+ else:
40
+ clear_tmp_dir(tmp_dir)
41
 
42
  video_path = os.path.join(tmp_dir, "video.mp4")
43
 
 
81
  f"**Transcript of the audio:**\n\n *{transcript.strip(' ')}*"
82
  )
83
 
 
84
  return summary
85
 
86
  except Exception as e: