Spaces:
Sleeping
Sleeping
File size: 1,389 Bytes
266eee8 b4eb3f6 266eee8 b4eb3f6 266eee8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import gradio as gr
from transformers import pipeline
from gtts import gTTS
import os
# Initialize Whisper for speech-to-text
whisper = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")
# Hardcoded knowledge base for Q&A
knowledge_base = {
"what cars are available": "We have Toyota Camry, Honda Civic, and Ford Mustang.",
"price of camry": "The Toyota Camry starts at $25,000."
}
def transcribe(audio):
return whisper(audio)["text"]
def text_to_speech(text):
tts = gTTS(text, lang="en")
tts.save("response.mp3")
return "response.mp3"
def answer_question(text):
for key in knowledge_base:
if key in text.lower():
return knowledge_base[key]
return "Sorry, I can help with car availability and prices. Try again!"
def process_audio(audio):
text = transcribe(audio)
response = answer_question(text)
audio_response = text_to_speech(response)
return response, audio_response
# Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# AI Support Agent: Car Dealership")
audio_input = gr.Audio(label="Speak to the Agent") # Removed 'type' parameter
text_output = gr.Textbox(label="Agent Response")
audio_output = gr.Audio(label="Listen to Response")
btn = gr.Button("Submit")
btn.click(fn=process_audio, inputs=audio_input, outputs=[text_output, audio_output])
demo.launch() |