akadriu commited on
Commit
192be9f
·
verified ·
1 Parent(s): e0c9526

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
2
  from transformers import pipeline
3
  import gradio as gr
4
-
5
 
6
  # Fetch the token from the environment
7
  hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
@@ -9,34 +9,37 @@ model_id = "akadriu/whisper-medium-sq" # update with your model id
9
  pipe = pipeline("automatic-speech-recognition", model=model_id, token=hf_token)
10
 
11
  def transcribe_speech(filepath):
 
 
 
 
12
  output = pipe(
13
  filepath,
14
  max_new_tokens=256,
15
  generate_kwargs={
16
  "task": "transcribe",
17
  "language": "albanian",
18
- }, # update with the language you've fine-tuned on
19
  chunk_length_s=30,
20
  batch_size=8,
21
  )
22
  return output["text"]
23
 
24
- import gradio as gr
25
-
26
- demo = gr.Blocks()
27
-
28
  mic_transcribe = gr.Interface(
29
  fn=transcribe_speech,
30
- inputs=gr.Audio(sources="microphone", type="filepath"),
31
  outputs="text",
32
  )
33
 
34
  file_transcribe = gr.Interface(
35
  fn=transcribe_speech,
36
- inputs=gr.Audio(sources="upload", type="filepath"),
37
  outputs="text",
38
  )
39
 
 
 
40
  with demo:
41
  gr.TabbedInterface(
42
  [mic_transcribe, file_transcribe],
@@ -44,3 +47,4 @@ with demo:
44
  )
45
 
46
  demo.launch(debug=True)
 
 
1
  import os
2
  from transformers import pipeline
3
  import gradio as gr
4
+ import numpy as np
5
 
6
  # Fetch the token from the environment
7
  hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
 
9
  pipe = pipeline("automatic-speech-recognition", model=model_id, token=hf_token)
10
 
11
  def transcribe_speech(filepath):
12
+ # Load the audio file into a numpy array
13
+ if filepath is None:
14
+ raise ValueError("No audio file provided.")
15
+
16
  output = pipe(
17
  filepath,
18
  max_new_tokens=256,
19
  generate_kwargs={
20
  "task": "transcribe",
21
  "language": "albanian",
22
+ },
23
  chunk_length_s=30,
24
  batch_size=8,
25
  )
26
  return output["text"]
27
 
28
+ # Create Gradio interface
 
 
 
29
  mic_transcribe = gr.Interface(
30
  fn=transcribe_speech,
31
+ inputs=gr.Audio(source="microphone", type="filepath"), # Removed plural from "sources"
32
  outputs="text",
33
  )
34
 
35
  file_transcribe = gr.Interface(
36
  fn=transcribe_speech,
37
+ inputs=gr.Audio(source="upload", type="filepath"), # Removed plural from "sources"
38
  outputs="text",
39
  )
40
 
41
+ demo = gr.Blocks()
42
+
43
  with demo:
44
  gr.TabbedInterface(
45
  [mic_transcribe, file_transcribe],
 
47
  )
48
 
49
  demo.launch(debug=True)
50
+