Falcon_Barista / app.py
darthPanda's picture
pre-alpha-release-v0.0
b9970ea
import gradio as gr
from asr_openai import AutomaticSpeechRecognition
from tts_elevenlabs import ElevenLabsTTS
from falcon_7b_llm import Falcon_7b_llm
import logging
import os
logging.basicConfig(level=logging.INFO)
def delete_files_in_folder(folder_path):
for filename in os.listdir(folder_path):
file_path = os.path.join(folder_path, filename)
# Check if it's a file (and not a directory)
if os.path.isfile(file_path):
os.remove(file_path)
def generate_response(input_audio):
sentence = asr.run_transcription(input_audio)
# sentence = 'how are you?'
print(sentence)
llm_response = llm.get_llm_response(sentence['text'])
output_audio = tts.tts_generate_audio(llm_response)
# output_audio = tts.tts_generate_audio(sentence)
chatbot_history.append(((input_audio,), (output_audio,)))
return chatbot_history
delete_files_in_folder('data//tts_responses')
title = "<h1 style='text-align: center; color: #ffffff; font-size: 40px;'> 🦅 Falcon Barista"
asr = AutomaticSpeechRecognition()
tts = ElevenLabsTTS()
llm = Falcon_7b_llm()
chatbot_history = []
def restart_chat():
delete_files_in_folder('data//tts_responses')
global chatbot_history
chatbot_history = []
tts.restart_state()
llm.restart_state()
return chatbot_history
with gr.Blocks() as demo:
gr.Markdown(title)
with gr.Row():
gr.Image('data//falcon.png', label="Look how cute is Falcon Barista")
with gr.Column():
chatbot = gr.Chatbot(label='Chat with Falcon Barista', avatar_images=('data//user_avatar_logo.png','data//falcon_logo_transparent.png'))
with gr.Row():
mic = gr.Audio(source="microphone", type='filepath', scale=3)
mic.stop_recording(generate_response, mic, chatbot)
restart_btn = gr.Button(value="Restart Chat", scale=1)
restart_btn.click(restart_chat, outputs=[chatbot])
if __name__ == "__main__":
demo.launch()