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()