File size: 2,385 Bytes
71736e8
5d557f1
71736e8
5d557f1
 
 
 
fd868fe
5d557f1
 
9e991a9
5d557f1
 
fd868fe
5d557f1
 
9e991a9
5d557f1
 
168235c
 
 
 
 
9e052e8
168235c
 
 
 
 
 
 
fd868fe
71736e8
 
 
 
9e991a9
5d557f1
 
 
 
 
 
 
168235c
5d557f1
168235c
5d557f1
 
71736e8
168235c
 
 
71736e8
 
5d557f1
168235c
 
5d557f1
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)