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"# {chatbot.name}\n\nWillkommen bei {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 erfolgreich geladen.") ) return ( gr.update(value="# Chatbot\n\nWillkommen beim Chatbot"), gr.update(value="", visible=True), gr.update(value=""), gr.update(value="Ungültige Chatbot-ID oder Chatbot nicht aktiv.") ) def create_chat_tab(chatbot_id_input, load_button, load_message): chatbot_title = gr.Markdown("# Chatbot\n\nWillkommen beim Chatbot") chat_interface = gr.ChatInterface( chat_with_bot, additional_inputs=[chatbot_id_input], ) share_link = gr.Textbox(label="Link zum Teilen", 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] ) # Fügen Sie eine benutzerdefinierte HTML-Schaltfläche hinzu, um die URL zum Teilen in die Zwischenablage zu kopieren 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)