barbaroo commited on
Commit
eb134bd
1 Parent(s): f9935f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -22
app.py CHANGED
@@ -1,54 +1,46 @@
1
  import gradio as gr
2
  import time
3
- import torch
4
  from transformers import pipeline
5
- import numpy as np
6
 
7
  # Check if GPU is available
8
  use_gpu = torch.cuda.is_available()
9
 
 
10
  # Configure the pipeline to use the GPU if available
11
  if use_gpu:
12
  p = pipeline("automatic-speech-recognition",
13
- model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h", device=0)
14
  else:
15
  p = pipeline("automatic-speech-recognition",
16
- model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h")
17
-
18
- chunk_size = 10 # Adjust the chunk size as needed
19
 
20
  def transcribe(audio, state="", uploaded_audio=None):
21
  if uploaded_audio is not None:
22
  audio = uploaded_audio
23
  if not audio:
24
  return state, state # Return a meaningful message
25
-
26
  try:
27
- state += "Transcribing...\n"
28
- if len(audio) <= chunk_size:
29
- text = p(audio)["text"]
30
- state += text + "\n"
31
- else:
32
- chunks = [audio[i:i + chunk_size] for i in range(0, len(audio), chunk_size)]
33
- for chunk in chunks:
34
- text = p(chunk)["text"]
35
- state += text + "\n"
36
- time.sleep(1) # Simulate processing time for each chunk
37
  return state, state
38
  except Exception as e:
39
  return "An error occurred during transcription.", state # Handle other exceptions
40
 
 
 
 
41
  gr.Interface(
42
  fn=transcribe,
43
  inputs=[
44
- gr.inputs.Audio(source="microphone", type="numpy"),
45
  'state',
46
- gr.inputs.Audio(label="Upload Audio File", type="numpy", source="upload")
47
  ],
48
  outputs=[
49
  "textbox",
50
  "state"
51
  ],
52
- live=True
53
- ).launch()
54
-
 
1
  import gradio as gr
2
  import time
 
3
  from transformers import pipeline
4
+ import torch
5
 
6
  # Check if GPU is available
7
  use_gpu = torch.cuda.is_available()
8
 
9
+
10
  # Configure the pipeline to use the GPU if available
11
  if use_gpu:
12
  p = pipeline("automatic-speech-recognition",
13
+ model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h", device=0)
14
  else:
15
  p = pipeline("automatic-speech-recognition",
16
+ model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h")
17
+
 
18
 
19
  def transcribe(audio, state="", uploaded_audio=None):
20
  if uploaded_audio is not None:
21
  audio = uploaded_audio
22
  if not audio:
23
  return state, state # Return a meaningful message
 
24
  try:
25
+ time.sleep(3)
26
+ text = p(audio)["text"]
27
+ state += text + "\n"
 
 
 
 
 
 
 
28
  return state, state
29
  except Exception as e:
30
  return "An error occurred during transcription.", state # Handle other exceptions
31
 
32
+
33
+
34
+
35
  gr.Interface(
36
  fn=transcribe,
37
  inputs=[
38
+ gr.inputs.Audio(source="microphone", type="filepath"),
39
  'state',
40
+ gr.inputs.Audio(label="Upload Audio File", type="filepath", source="upload")
41
  ],
42
  outputs=[
43
  "textbox",
44
  "state"
45
  ],
46
+ live=True).launch()