dschandra commited on
Commit
abb5d10
·
verified ·
1 Parent(s): 88a98a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -3,6 +3,7 @@ import torch
3
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
4
  from gtts import gTTS
5
  import os
 
6
 
7
  # Load Wav2Vec2 model and processor for speech-to-text
8
  processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h")
@@ -25,7 +26,6 @@ def speech_to_text(audio_file):
25
 
26
  def generate_response(text):
27
  # Using Hugging Face to generate a text-based response
28
- # Use any model like DialoGPT for text response generation
29
  conversational_pipeline = pipeline("text-generation", model="microsoft/DialoGPT-medium")
30
  response = conversational_pipeline(text, max_length=50)
31
  return response[0]['generated_text']
@@ -51,8 +51,8 @@ def process_audio(audio_file):
51
  # Create Gradio interface for audio input/output
52
  iface = gr.Interface(
53
  fn=process_audio,
54
- inputs=gr.inputs.Audio(source="microphone", type="file"),
55
- outputs=[gr.outputs.Textbox(), gr.outputs.Audio(type="file")],
56
  live=True,
57
  title="Voice Bot with Wav2Vec2.0",
58
  description="Speak to the bot and get a response!"
 
3
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
4
  from gtts import gTTS
5
  import os
6
+ import librosa
7
 
8
  # Load Wav2Vec2 model and processor for speech-to-text
9
  processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h")
 
26
 
27
  def generate_response(text):
28
  # Using Hugging Face to generate a text-based response
 
29
  conversational_pipeline = pipeline("text-generation", model="microsoft/DialoGPT-medium")
30
  response = conversational_pipeline(text, max_length=50)
31
  return response[0]['generated_text']
 
51
  # Create Gradio interface for audio input/output
52
  iface = gr.Interface(
53
  fn=process_audio,
54
+ inputs=gr.Audio(source="microphone", type="file"), # Updated for Gradio v3.x
55
+ outputs=[gr.Textbox(), gr.Audio(type="file")], # Updated for Gradio v3.x
56
  live=True,
57
  title="Voice Bot with Wav2Vec2.0",
58
  description="Speak to the bot and get a response!"