Tobias Geisler
new Random Fact example bot
9e052e8
raw
history blame
2.39 kB
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 = gr.Textbox(label="Chatbot-ID eingeben")
# Add examples right below the chatbot ID input field
examples = gr.Examples(
examples=["courteous-duckling-628", "delightful-red-panda-273", "glowing-toucan-982", "mellow-toucan-512", "upbeat-elephant-433", "shiny-platypus-699"],
inputs=chatbot_id_input,
label="Beispiel-Chatbots"
)
load_button = gr.Button("Chatbot laden")
load_message = gr.Textbox(label="Lademeldung", interactive=False)
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]
)
# Add a custom HTML button for copying the share URL to the clipboard
copy_button = gr.HTML("""
<button onclick="copyToClipboard('share_link')">In die Zwischenablage kopieren</button>
""")
return {
"chatbot_id_input": chatbot_id_input,
"load_button": load_button,
"load_message": load_message,
"title": chatbot_title,
"interface": chat_interface,
"share_link": share_link,
"copy_button": copy_button,
"examples": examples
}
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)