harshananddev commited on
Commit
fb2299d
·
verified ·
1 Parent(s): 8a8c358

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -2,17 +2,6 @@ import gradio as gr
2
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
3
  import torch
4
  import torchaudio
5
- import subprocess
6
- import sys
7
-
8
- # Function to install required packages
9
- def install(package):
10
- subprocess.check_call([sys.executable, "-m", "pip", "install", package])
11
-
12
- install("transformers")
13
- install("torch")
14
- install("torchaudio")
15
- install("gradio")
16
 
17
  # Load pre-trained model and processor
18
  model_name = "facebook/wav2vec2-base-960h"
@@ -21,8 +10,11 @@ model = Wav2Vec2ForCTC.from_pretrained(model_name)
21
 
22
  def speech_to_text(audio):
23
  try:
 
 
 
24
  # Load audio file
25
- waveform, rate = torchaudio.load(audio.name)
26
 
27
  # Ensure the audio is mono
28
  if waveform.shape[0] > 1:
@@ -50,8 +42,8 @@ def speech_to_text(audio):
50
  # Create Gradio interface
51
  iface = gr.Interface(
52
  fn=speech_to_text,
53
- inputs=gr.Audio(type="filepath"),
54
- outputs="text",
55
  live=True,
56
  title="Speech to Text",
57
  description="Speak into your microphone and get the transcribed text."
 
2
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
3
  import torch
4
  import torchaudio
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Load pre-trained model and processor
7
  model_name = "facebook/wav2vec2-base-960h"
 
10
 
11
  def speech_to_text(audio):
12
  try:
13
+ if audio is None:
14
+ return "No audio file provided."
15
+
16
  # Load audio file
17
+ waveform, rate = torchaudio.load(audio)
18
 
19
  # Ensure the audio is mono
20
  if waveform.shape[0] > 1:
 
42
  # Create Gradio interface
43
  iface = gr.Interface(
44
  fn=speech_to_text,
45
+ inputs=gr.Audio(type="filepath", label="Input Audio"),
46
+ outputs=gr.Textbox(label="Transcription"),
47
  live=True,
48
  title="Speech to Text",
49
  description="Speak into your microphone and get the transcribed text."