import gradio as gr #from gtts import gTTS # Global variables chat_histories = {} current_chat_id = 0 # object creation css = """footer {visibility: hidden} .gradio-container {background: url('https://i0.wp.com/www.flexpowersystems.com/wp-content/uploads/2020/08/shutterstock_1251830596-scaled-1.jpg');repeat 0 0;} """ with gr.Blocks(theme=gr.themes.Soft(),css=css) as demo: #https://i.gifer.com/J4o.gif #https://i0.wp.com/www.flexpowersystems.com/wp-content/uploads/2020/08/shutterstock_1251830596-scaled-1.jpg #https://static.wixstatic.com/media/5cfe14_30977ca5f4d04cc2a8977a980baf19a9~mv2.gif with gr.Row(visible=False) as login: with gr.Column(2): user = gr.Textbox(label="Username",visible=False) with gr.Column(1): gr.HTML(value="



Welcome

") user = gr.Textbox(label="Username") password = gr.Textbox(label="password") submit_btn = gr.Button("Signin") with gr.Column(2): user = gr.Textbox(label="Username",visible=False) with gr.Column() as main: #with gr.Accordion("See Details"): #gr.Markdown("hhhhhhh") with gr.Tab("Chatbot"): 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="Previous Chat histories",placeholder="Chat names not found", lines=17) dropdown = gr.Dropdown(label="Select to load Previous chat",choices=["no chat found"]) # Second Column with 80% width with gr.Column(scale=6): chatbot = gr.Chatbot([[None,"Hi there, what brings you here today?"]],avatar_images=("https://cdnl.iconscout.com/lottie/premium/thumb/user-profile-5568736-4644453.gif","https://cdn.dribbble.com/users/77598/screenshots/16399264/media/d86ceb1ad552398787fb76f343080aa6.gif"),height=460,show_label=False,show_copy_button=True,show_share_button=True,likeable=True,layout="bubble") with gr.Tab("text input (after typing press enter)"): msg = gr.Textbox(show_label=False,placeholder="type anything and press enter") with gr.Tab("voice input"): audio_input = gr.Microphone(label="Press start record to speak", type="filepath") with gr.Tab("Setup your own voice"): audio_input = gr.Microphone(label="Press start record to speak and add your voice", type="filepath") with gr.Tab("Select the language"): dropdown = gr.Dropdown(label="select language",choices=["english"]) def submit(t): return gr.Column(visible=True),gr.Row(visible=False) submit_btn.click(submit,audio_input,[main,login]) 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?"]],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]) msg.submit(respond, [msg, chatbot], [msg, chatbot]) save_button.click(save_chat, [chatbot], outputs=[display_chat_names,chatbot,dropdown]) # Added display_chat_names as an output demo.launch()