muhtasham commited on
Commit
eb5510b
·
1 Parent(s): 0147bd5
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -20,7 +20,7 @@ def check_ffmpeg():
20
  # Initialize ffmpeg check
21
  check_ffmpeg()
22
 
23
- def transcribe(inputs):
24
  if inputs is None:
25
  logger.warning("No audio file submitted")
26
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
@@ -39,7 +39,7 @@ def transcribe(inputs):
39
 
40
  # Add parameters to request
41
  params = {
42
- "return_timestamps": True
43
  }
44
  logger.debug(f"Request parameters: {params}")
45
 
@@ -60,12 +60,12 @@ def transcribe(inputs):
60
 
61
  # Format response as JSON
62
  formatted_result = {
63
- "text": result["text"],
64
- "chunks": []
65
  }
66
 
67
- if "chunks" in result:
68
  logger.info(f"Processing {len(result['chunks'])} chunks")
 
69
  for i, chunk in enumerate(result["chunks"]):
70
  logger.debug(f"Processing chunk {i}: {chunk}")
71
  try:
@@ -83,14 +83,8 @@ def transcribe(inputs):
83
  except Exception as chunk_error:
84
  logger.error(f"Error processing chunk {i}: {str(chunk_error)}")
85
  continue
86
- else:
87
- logger.info("No chunks found, using single chunk")
88
- formatted_result["chunks"].append({
89
- "text": result["text"],
90
- "timestamp": [0.0, None]
91
- })
92
 
93
- logger.info(f"Successfully processed transcription with {len(formatted_result['chunks'])} chunks")
94
  return formatted_result
95
  except Exception as e:
96
  logger.exception(f"Error during transcription: {str(e)}")
@@ -102,6 +96,7 @@ mf_transcribe = gr.Interface(
102
  fn=transcribe,
103
  inputs=[
104
  gr.Audio(sources="microphone", type="filepath"),
 
105
  ],
106
  outputs=[
107
  gr.JSON(label="Transcription", open=True),
@@ -123,6 +118,7 @@ file_transcribe = gr.Interface(
123
  fn=transcribe,
124
  inputs=[
125
  gr.Audio(sources="upload", type="filepath", label="Audio file"),
 
126
  ],
127
  outputs=[
128
  gr.JSON(label="Transcription", open=True),
 
20
  # Initialize ffmpeg check
21
  check_ffmpeg()
22
 
23
+ def transcribe(inputs, return_timestamps):
24
  if inputs is None:
25
  logger.warning("No audio file submitted")
26
  raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
 
39
 
40
  # Add parameters to request
41
  params = {
42
+ "return_timestamps": return_timestamps
43
  }
44
  logger.debug(f"Request parameters: {params}")
45
 
 
60
 
61
  # Format response as JSON
62
  formatted_result = {
63
+ "text": result["text"]
 
64
  }
65
 
66
+ if return_timestamps and "chunks" in result:
67
  logger.info(f"Processing {len(result['chunks'])} chunks")
68
+ formatted_result["chunks"] = []
69
  for i, chunk in enumerate(result["chunks"]):
70
  logger.debug(f"Processing chunk {i}: {chunk}")
71
  try:
 
83
  except Exception as chunk_error:
84
  logger.error(f"Error processing chunk {i}: {str(chunk_error)}")
85
  continue
86
+ logger.info(f"Successfully processed transcription with {len(formatted_result['chunks'])} chunks")
 
 
 
 
 
87
 
 
88
  return formatted_result
89
  except Exception as e:
90
  logger.exception(f"Error during transcription: {str(e)}")
 
96
  fn=transcribe,
97
  inputs=[
98
  gr.Audio(sources="microphone", type="filepath"),
99
+ gr.Checkbox(label="Include timestamps", value=True),
100
  ],
101
  outputs=[
102
  gr.JSON(label="Transcription", open=True),
 
118
  fn=transcribe,
119
  inputs=[
120
  gr.Audio(sources="upload", type="filepath", label="Audio file"),
121
+ gr.Checkbox(label="Include timestamps", value=True),
122
  ],
123
  outputs=[
124
  gr.JSON(label="Transcription", open=True),