| import gradio as gr |
| |
| |
| chat_histories = {} |
| current_chat_id = 0 |
| |
|
|
| from env import env |
|
|
| |
| variable_value = env.class_attribute |
|
|
| |
| print(variable_value) |
|
|
| with gr.Blocks() as demo: |
|
|
| with gr.Row(): |
| |
| |
| 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() |
|
|
| |
| |
| 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): |
| |
| 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): |
| |
| chat_name = entered_chat_name |
| print(chat_name) |
| 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]) |
| load_button.click(load_chat, [enter_chat_name], outputs=[msg,chatbot]) |
|
|
|
|
| demo.launch() |
|
|