Update app.py
Browse files
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.
|
| 55 |
-
outputs=[gr.
|
| 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!"
|