raygiles3 commited on
Commit
d1dd3f0
·
verified ·
1 Parent(s): 28b4e15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -16
app.py CHANGED
@@ -1,22 +1,28 @@
1
  import torch
2
  from transformers import pipeline
 
3
 
4
- # Initialize the speech-to-text pipeline from Hugging Face Transformers
5
- # This uses the "openai/whisper-tiny.en" model for automatic speech recognition (ASR)
6
- # The `chunk_length_s` parameter specifies the chunk length in seconds for processing
7
- pipe = pipeline(
8
- "automatic-speech-recognition",
9
- model="openai/whisper-tiny.en",
10
- chunk_length_s=30,
11
- )
 
 
 
12
 
13
- # Define the path to the audio file that needs to be transcribed
14
- sample = 'downloaded_audio.mp3'
 
15
 
16
- # Perform speech recognition on the audio file
17
- # The `batch_size=8` parameter indicates how many chunks are processed at a time
18
- # The result is stored in `prediction` with the key "text" containing the transcribed text
19
- prediction = pipe(sample, batch_size=8)["text"]
 
20
 
21
- # Print the transcribed text to the console
22
- print(prediction)
 
1
  import torch
2
  from transformers import pipeline
3
+ import gradio as gr
4
 
5
+ # Function to transcribe audio using the OpenAI Whisper model
6
+ def transcript_audio(audio_file):
7
+ # Initialize the speech recognition pipeline
8
+ pipe = pipeline(
9
+ "automatic-speech-recognition",
10
+ model="openai/whisper-tiny.en",
11
+ chunk_length_s=30,
12
+ )
13
+ # Transcribe the audio file and return the result
14
+ result = pipe(audio_file, batch_size=8)["text"]
15
+ return result
16
 
17
+ # Set up Gradio interface
18
+ audio_input = gr.Audio(sources="upload", type="filepath") # Audio input
19
+ output_text = gr.Textbox() # Text output
20
 
21
+ # Create the Gradio interface with the function, inputs, and outputs
22
+ iface = gr.Interface(fn=transcript_audio,
23
+ inputs=audio_input, outputs=output_text,
24
+ title="Audio Transcription App",
25
+ description="Upload the audio file")
26
 
27
+ # Launch the Gradio app
28
+ iface.launch()