Bhaskar2611 commited on
Commit
912b759
·
verified ·
1 Parent(s): 94e9c18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -23
app.py CHANGED
@@ -1,39 +1,36 @@
1
-
2
  import whisper
3
  import gradio as gr
4
- import pyperclip # Add this to requirements.txt
5
 
6
  model = whisper.load_model("small")
7
 
8
  def transcribe(audio):
 
 
 
9
  audio = whisper.load_audio(audio)
10
  audio = whisper.pad_or_trim(audio)
11
 
 
12
  mel = whisper.log_mel_spectrogram(audio).to(model.device)
 
 
13
  _, probs = model.detect_language(mel)
14
  print(f"Detected language: {max(probs, key=probs.get)}")
15
 
16
- options = whisper.DecodingOptions(fp16=False)
 
17
  result = whisper.decode(model, mel, options)
18
  return result.text
19
-
20
- def copy_to_clipboard(text):
21
- pyperclip.copy(text)
22
- return "Copied!"
23
-
24
- with gr.Blocks() as demo:
25
- gr.Markdown("## Product Recommendations System Text")
26
 
27
- audio_input = gr.Audio(source="microphone", type="filepath", label="Speak Here")
28
- output_text = gr.Textbox(label="Transcribed Text", interactive=True)
29
- copy_status = gr.Textbox(label="Copy Status", interactive=False)
30
-
31
- with gr.Row():
32
- transcribe_btn = gr.Button("Transcribe")
33
- copy_btn = gr.Button("Copy Text")
34
-
35
- transcribe_btn.click(transcribe, inputs=audio_input, outputs=output_text)
36
- copy_btn.click(copy_to_clipboard, inputs=output_text, outputs=copy_status)
37
-
38
- demo.launch()
39
-
 
 
1
  import whisper
2
  import gradio as gr
 
3
 
4
  model = whisper.load_model("small")
5
 
6
  def transcribe(audio):
7
+
8
+ #time.sleep(3)
9
+ # load audio and pad/trim it to fit 30 seconds
10
  audio = whisper.load_audio(audio)
11
  audio = whisper.pad_or_trim(audio)
12
 
13
+ # make log-Mel spectrogram and move to the same device as the model
14
  mel = whisper.log_mel_spectrogram(audio).to(model.device)
15
+
16
+ # detect the spoken language
17
  _, probs = model.detect_language(mel)
18
  print(f"Detected language: {max(probs, key=probs.get)}")
19
 
20
+ # decode the audio
21
+ options = whisper.DecodingOptions(fp16 = False)
22
  result = whisper.decode(model, mel, options)
23
  return result.text
 
 
 
 
 
 
 
24
 
25
+
26
+
27
+ gr.Interface(
28
+ title = 'Product Recommendation System Text',
29
+ fn=transcribe,
30
+ inputs=[
31
+ gr.inputs.Audio(source="microphone", type="filepath")
32
+ ],
33
+ outputs=[
34
+ "textbox"
35
+ ],
36
+ live=True).launch()