rbcurzon commited on
Commit
25b58c8
·
1 Parent(s): 490e302

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -29,6 +29,10 @@ from transformers import (
29
  AutoTokenizer,
30
  )
31
 
 
 
 
 
32
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
33
 
34
  # load model and processor
@@ -147,12 +151,11 @@ async def translate_audio(
147
  "srcLang": srcLang,
148
  "tgtLang": tgtLang
149
  }
150
- print(result_dict)
151
 
152
  return result_dict
153
 
154
  except Exception as error:
155
- print("Error: ", str(error))
156
  raise HTTPException(status_code=500, detail=str(error))
157
 
158
  finally:
@@ -169,8 +172,10 @@ async def translate_text(text: str,
169
  srcLang: str = Form(...),
170
  tgtLang: str = Form(...)):
171
  result = translate(text, srcLang, tgtLang)
172
- print('Raw: ', text)
173
- print('Translated: ', result)
 
 
174
 
175
  result_dict = {
176
  "text": text,
@@ -199,8 +204,9 @@ async def synthesize(text: str):
199
  temp_file,
200
  rate=model.config.sampling_rate,
201
  data=data_np_squeezed
202
- )
203
-
 
204
  return FileResponse(
205
  temp_file,
206
  media_type="audio/wav",
 
29
  AutoTokenizer,
30
  )
31
 
32
+ import logging
33
+ logging.basicConfig(level=logging.INFO
34
+ , format='%(asctime)s - %(levelname)s - %(message)s')
35
+
36
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
37
 
38
  # load model and processor
 
151
  "srcLang": srcLang,
152
  "tgtLang": tgtLang
153
  }
 
154
 
155
  return result_dict
156
 
157
  except Exception as error:
158
+ logging.error(f"Error translating audio {file.filename}: {error}")
159
  raise HTTPException(status_code=500, detail=str(error))
160
 
161
  finally:
 
172
  srcLang: str = Form(...),
173
  tgtLang: str = Form(...)):
174
  result = translate(text, srcLang, tgtLang)
175
+
176
+ if not result:
177
+ logging.error("Translation failed for text: %s", text)
178
+ raise HTTPException(status_code=500, detail="Translation failed")
179
 
180
  result_dict = {
181
  "text": text,
 
204
  temp_file,
205
  rate=model.config.sampling_rate,
206
  data=data_np_squeezed
207
+ )
208
+ logging.info(f"Synthesizing completed for text: {text}")
209
+
210
  return FileResponse(
211
  temp_file,
212
  media_type="audio/wav",