import gradio as gr from database import get_chatbot def load_chatbot(chatbot_id): chatbot = get_chatbot(chatbot_id) if chatbot: return ( gr.update(value=f"Welcome to {chatbot.name}"), gr.update(value=chatbot_id, visible=True), gr.update(value=f"https://huggingface.co/spaces/codora/ai-app-creator?chatbot_id={chatbot_id}"), gr.update(value="Chatbot loaded successfully.") ) return ( gr.update(value="Welcome to the Chatbot"), gr.update(value="", visible=True), gr.update(value=""), gr.update(value="Invalid chatbot ID or chatbot not active.") ) def create_chat_tab(chatbot_id_input, load_button, load_message): chatbot_title = gr.Markdown("Welcome to the Chatbot") chat_interface = gr.ChatInterface( chat_with_bot, additional_inputs=[chatbot_id_input], ) share_link = gr.Textbox(label="Share Link", interactive=False, elem_id="share_link") load_button.click( fn=load_chatbot, inputs=[chatbot_id_input], outputs=[chatbot_title, chatbot_id_input, share_link, load_message] ) # Add a custom HTML button for copying the share URL to the clipboard copy_button = gr.HTML(""" """) return { "title": chatbot_title, "interface": chat_interface, "share_link": share_link, "copy_button": copy_button } def chat_with_bot(message, history, chatbot_id): from utils.openai_utils import chat_with_bot as openai_chat_with_bot return openai_chat_with_bot(message, history, chatbot_id)