File size: 2,002 Bytes
b9970ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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()