File size: 3,738 Bytes
b9970ea
0283b01
b9970ea
 
 
0283b01
b9970ea
 
 
 
 
 
5aa0262
 
b9970ea
 
 
 
 
 
 
 
 
 
 
0283b01
 
 
 
 
 
 
b9970ea
0283b01
b9970ea
 
 
 
 
 
 
748662c
b9970ea
 
 
 
0283b01
b9970ea
0283b01
 
b9970ea
0283b01
 
 
 
 
 
b9970ea
 
 
748662c
 
 
 
0283b01
b9970ea
b0074a6
b9970ea
0283b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import gradio as gr
import pandas as pd
from asr_openai import AutomaticSpeechRecognition
from tts_elevenlabs import ElevenLabsTTS
from falcon_7b_llm import Falcon_7b_llm
from order_parser import Order_Parser
import logging
import os

logging.basicConfig(level=logging.INFO)

def delete_files_in_folder(folder_path):
    if not os.path.exists(folder_path):
        os.makedirs(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)
    global order_dict
    try:
        order_dict = order_taking.order_parser(sentence['text'])
        print(order_dict)
    except Exception as e:
        print('order parsing failed')
        print(e)
    llm_response = llm.get_llm_response(sentence['text'])
    print(llm_response)
    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 - Proof of Concept (POC)"

asr = AutomaticSpeechRecognition()
tts = ElevenLabsTTS()
llm = Falcon_7b_llm()
order_taking = Order_Parser()
chatbot_history = []
order_display=False
order_dict={}

df = pd.DataFrame({
    "item" : [], 
    "quantity" : [], 
}) 

s = df#.style.format("{:.2f}")

with gr.Blocks() as demo:
    gr.Markdown(title)
    gr.Markdown('''Note: This is just a POC and has several issues
1. High Latency
2. Models are still in fine tuning phase and get confused easily
                ''')
    order_title = gr.Markdown('### Your Order', visible=False)
    with gr.Row():
        gr.Image('https://i.imgur.com/fHCFI2T.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'), scale=2)
            mic = gr.Audio(source="microphone", type='filepath', scale=1)
            mic.stop_recording(generate_response, mic, chatbot)
    with gr.Row():
        restart_btn = gr.Button(value="Restart Chat", scale=1, variant='stop')
        # restart_btn.click(restart_chat, outputs=[chatbot])
        end_btn = gr.Button(value="End Chat and Confirm Order", scale=2, variant='primary')
        
    with gr.Column(visible=False) as output_col:
        order_title = gr.Markdown('### Your Order')
        order_summary = gr.DataFrame(s)

    def restart_chat():
        delete_files_in_folder('data//tts_responses')
        global chatbot_history
        chatbot_history = []
        global order_dict
        order_dict = {}
        global df
        df = pd.DataFrame({
            "item" : [], 
            "quantity" : [], 
        })
        order_taking.restart_state() 
        tts.restart_state()
        llm.restart_state()
        return {
            chatbot: [],
            output_col: gr.Column(visible=False)
        }

    def end_chat():
        df = pd.DataFrame(list(order_dict.items()), columns=['item', 'quantity'])

        s = df#.style.format("{:.2f}")
        return {
            output_col: gr.Column(visible=True),
            order_summary: gr.DataFrame(s, visible=True)
            }

    restart_btn.click(restart_chat, outputs=[chatbot, output_col])
    end_btn.click(end_chat, outputs=[output_col, order_summary])

if __name__ == "__main__":
    demo.launch()