File size: 2,917 Bytes
463b2fa
3cc37b1
973d67c
 
 
a5be8da
3cc37b1
c91f3ab
 
 
 
 
 
 
 
110ae1d
973d67c
c77e1df
 
 
d6f51e9
a9fa9e3
d48ea63
 
 
 
c77e1df
 
 
a9fa9e3
3f64b59
 
 
81b95ef
 
 
061c61d
81b95ef
 
973d67c
 
 
 
2a7bef1
973d67c
 
 
 
12c0b58
973d67c
b8917df
d7cf4e9
e1910c5
a4118e0
973d67c
c10b365
 
d509b41
 
c10b365
 
 
 
110ae1d
d509b41
12c0b58
2a7bef1
a4118e0
e266418
110ae1d
c1e857e
110ae1d
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
import gradio as gr
#from gtts import gTTS
# Global variables
chat_histories = {}
current_chat_id = 0
 # object creation

from env import env

# Access the class attribute
variable_value = env.class_attribute

# Print the value
print(variable_value)

with gr.Blocks() as demo:

    with gr.Row():
        
        # First Column with 20% width
        with gr.Column(scale=1):
            save_button = gr.Button("Start new Chat")
            display_chat_names = gr.Textbox(label="Chat histories",placeholder="Chat names not found", lines=16)
            dropdown = gr.Dropdown(label="just Select to load chat",choices=["no chat found"])
            enter_chat_name = gr.Textbox(label="just enter the number to load chat",placeholder="1")
            load_button = gr.Button()

        
        # Second Column with 80% width
        with gr.Column(scale=5):
            with gr.Row():
                        display_chat_names = gr.Textbox(label="Chat histories",placeholder="Chat names not found", lines=16)
                        dropdown = gr.Dropdown(label="just Select to load chat",choices=["no chat found"])
            with gr.Row():
                chatbot = gr.Chatbot([[None,"Hi there, what brings you here today?"]])
                msg = gr.Textbox()
                audio_input = gr.Microphone(label="Press start recording to speak", type="filepath")
                clear = gr.ClearButton([msg, chatbot])
                audio_input2 = gr.Audio(visible=False)

    def respond(message, chat_history):
        # Basic echo response
        chat_history.append((message, "message"))
        return "", chat_history

    def save_chat(chat_history):
        global current_chat_id
        current_chat_id += 1
        chat_name = f"chat history {current_chat_id}"
        chat_histories[chat_name] = chat_history
        chat_names = "\n".join(chat_histories.keys())
        print(chat_names.split("\n"))
        new_choices = gr.Dropdown(choices = chat_names.split("\n"),label = "just Select to load chat")
        return str(chat_names),[[None,"Hi there, what brings you here today?"]],"input.wav",new_choices

    def load_chat(entered_chat_name):
        # Fetch the specific chat history based on provided name
        chat_name = entered_chat_name
        print(chat_name)# Remove any trailing or leading spaces
        if chat_name in chat_histories:
            return "", chat_histories[chat_name]
        else:
            return "Chat not found!", []

    dropdown.select(load_chat, [dropdown], outputs=[msg,chatbot])
    enter_chat_name.change(load_chat, [enter_chat_name], outputs=[msg,chatbot])
    msg.submit(respond, [msg, chatbot], [msg, chatbot])
    save_button.click(save_chat, [chatbot], outputs=[display_chat_names,chatbot,audio_input2,dropdown])  # Added display_chat_names as an output
    load_button.click(load_chat, [enter_chat_name], outputs=[msg,chatbot])


demo.launch()