csukuangfj commited on
Commit
682c8c3
·
1 Parent(s): 248c236

replace logging.info with print

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -48,9 +48,9 @@ def convert_to_wav(in_filename: str) -> str:
48
  out_filename = str(uuid.uuid4())
49
  out_filename = f"{in_filename}.wav"
50
 
51
- logging.info(f"Converting '{in_filename}' to '{out_filename}'")
52
  _ = os.system(
53
- f"ffmpeg -hide_banner -i '{in_filename}' -ar 16000 -ac 1 '{out_filename}' -y"
54
  )
55
 
56
  return out_filename
@@ -74,7 +74,7 @@ def process_url(
74
  add_punct: str,
75
  url: str,
76
  ):
77
- logging.info(f"Processing URL: {url}")
78
  with tempfile.NamedTemporaryFile() as f:
79
  try:
80
  urllib.request.urlretrieve(url, f.name)
@@ -88,7 +88,7 @@ def process_url(
88
  add_punct=add_punct,
89
  )
90
  except Exception as e:
91
- logging.info(str(e))
92
  return "", build_html_output(str(e), "result_item_error")
93
 
94
 
@@ -107,7 +107,7 @@ def process_uploaded_file(
107
  "result_item_error",
108
  )
109
 
110
- logging.info(f"Processing uploaded file: {in_filename}")
111
  try:
112
  return process(
113
  in_filename=in_filename,
@@ -118,7 +118,7 @@ def process_uploaded_file(
118
  add_punct=add_punct,
119
  )
120
  except Exception as e:
121
- logging.info(str(e))
122
  return "", build_html_output(str(e), "result_item_error")
123
 
124
 
@@ -138,7 +138,7 @@ def process_microphone(
138
  "result_item_error",
139
  )
140
 
141
- logging.info(f"Processing microphone: {in_filename}")
142
  try:
143
  return process(
144
  in_filename=in_filename,
@@ -149,7 +149,7 @@ def process_microphone(
149
  add_punct=add_punct,
150
  )
151
  except Exception as e:
152
- logging.info(str(e))
153
  return "", build_html_output(str(e), "result_item_error")
154
 
155
 
@@ -162,17 +162,17 @@ def process(
162
  add_punct: str,
163
  in_filename: str,
164
  ):
165
- logging.info(f"language: {language}")
166
- logging.info(f"repo_id: {repo_id}")
167
- logging.info(f"decoding_method: {decoding_method}")
168
- logging.info(f"num_active_paths: {num_active_paths}")
169
- logging.info(f"in_filename: {in_filename}")
170
 
171
  filename = convert_to_wav(in_filename)
172
 
173
  now = datetime.now()
174
  date_time = now.strftime("%Y-%m-%d %H:%M:%S.%f")
175
- logging.info(f"Started at {date_time}")
176
 
177
  start = time.time()
178
 
@@ -194,7 +194,7 @@ def process(
194
  duration = metadata.num_frames / sample_rate
195
  rtf = (end - start) / duration
196
 
197
- logging.info(f"Finished at {date_time} s. Elapsed: {end - start: .3f} s")
198
 
199
  info = f"""
200
  Wave duration : {duration: .3f} s <br/>
@@ -207,8 +207,8 @@ def process(
207
  "Please run again to measure the real RTF.<br/>"
208
  )
209
 
210
- logging.info(info)
211
- logging.info(f"\nrepo_id: {repo_id}\nhyp: {text}")
212
 
213
  return text, build_html_output(info)
214
 
 
48
  out_filename = str(uuid.uuid4())
49
  out_filename = f"{in_filename}.wav"
50
 
51
+ print(f"Converting '{in_filename}' to '{out_filename}'")
52
  _ = os.system(
53
+ f"ffmpeg -hide_banner -loglevel error -i '{in_filename}' -ar 16000 -ac 1 '{out_filename}' -y"
54
  )
55
 
56
  return out_filename
 
74
  add_punct: str,
75
  url: str,
76
  ):
77
+ print(f"Processing URL: {url}")
78
  with tempfile.NamedTemporaryFile() as f:
79
  try:
80
  urllib.request.urlretrieve(url, f.name)
 
88
  add_punct=add_punct,
89
  )
90
  except Exception as e:
91
+ print(str(e))
92
  return "", build_html_output(str(e), "result_item_error")
93
 
94
 
 
107
  "result_item_error",
108
  )
109
 
110
+ print(f"Processing uploaded file: {in_filename}")
111
  try:
112
  return process(
113
  in_filename=in_filename,
 
118
  add_punct=add_punct,
119
  )
120
  except Exception as e:
121
+ print(str(e))
122
  return "", build_html_output(str(e), "result_item_error")
123
 
124
 
 
138
  "result_item_error",
139
  )
140
 
141
+ print(f"Processing microphone: {in_filename}")
142
  try:
143
  return process(
144
  in_filename=in_filename,
 
149
  add_punct=add_punct,
150
  )
151
  except Exception as e:
152
+ print(str(e))
153
  return "", build_html_output(str(e), "result_item_error")
154
 
155
 
 
162
  add_punct: str,
163
  in_filename: str,
164
  ):
165
+ print(f"language: {language}")
166
+ print(f"repo_id: {repo_id}")
167
+ print(f"decoding_method: {decoding_method}")
168
+ print(f"num_active_paths: {num_active_paths}")
169
+ print(f"in_filename: {in_filename}")
170
 
171
  filename = convert_to_wav(in_filename)
172
 
173
  now = datetime.now()
174
  date_time = now.strftime("%Y-%m-%d %H:%M:%S.%f")
175
+ print(f"Started at {date_time}")
176
 
177
  start = time.time()
178
 
 
194
  duration = metadata.num_frames / sample_rate
195
  rtf = (end - start) / duration
196
 
197
+ print(f"Finished at {date_time} s. Elapsed: {end - start: .3f} s")
198
 
199
  info = f"""
200
  Wave duration : {duration: .3f} s <br/>
 
207
  "Please run again to measure the real RTF.<br/>"
208
  )
209
 
210
+ print(info)
211
+ print(f"\nrepo_id: {repo_id}\nhyp: {text}")
212
 
213
  return text, build_html_output(info)
214