File size: 1,768 Bytes
6d15e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
857404b
79bb89f
6d15e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fec8a1d
6d15e78
 
 
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
import gradio as gr
from dotenv import load_dotenv
from gradio import ChatMessage
from setup import  Speech_Text
from temp import Script
load_dotenv()

transcriptor = Speech_Text()
output_id = None
database_con = Script()

# Function to generate chatbot response
def generate_response(chat_history: list[ChatMessage]):
    return database_con.request(chat_history)

def process(audio, input_text, chat_history: list[ChatMessage]):

    if audio is not None:
        transcript = transcriptor.get_transcript(audio)
        chat_history.append({"role": "user", "content": transcript})

    elif input_text:
        chat_history.append({"role": "user", "content": input_text})

    else:
        response = 'Provide a query text or an audio to query.'
        chat_history.append({"role": "assistant", "content": response})
        # audio_data = transcriptor.speech_synthesis(response)
        return chat_history

    response = generate_response(chat_history)
    chat_history.append({"role": "assistant", "content": response})
    # audio_data = transcriptor.speech_synthesis(response)
    return chat_history

# Create Gradio Blocks interface
with gr.Blocks() as demo:
    
    with gr.Row():
        chatbot = gr.Chatbot(label="Chatbot Conversation", type="messages", bubble_full_width=True, show_copy_button=True, autoscroll=True)
    
    with gr.Row():
        input_textbox = gr.Textbox(label="Input Text", placeholder="Type your message here...")
        input_audio = gr.Audio(label="Input Audio", sources="microphone", type="numpy")
    
    process_button = gr.Button("Submit Query")

    process_button.click(
        fn=process,
        inputs=[input_audio, input_textbox, chatbot],
        outputs=[chatbot])

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