Spaces:
Sleeping
Sleeping
Tobias Geisler
commited on
Commit
·
168235c
1
Parent(s):
6ba3c65
Move Chatbot Loading Logic to Chat Tab
Browse files- app.py +7 -16
- tabs/chat.py +20 -4
app.py
CHANGED
|
@@ -18,21 +18,12 @@ def create_app():
|
|
| 18 |
}
|
| 19 |
</script>
|
| 20 |
"""
|
| 21 |
-
) as
|
| 22 |
gr.Markdown("# codora KI-App-Ersteller v0")
|
| 23 |
-
chatbot_id_input = gr.Textbox(label="Chatbot-ID eingeben")
|
| 24 |
-
load_button = gr.Button("Chatbot laden")
|
| 25 |
-
load_message = gr.Textbox(label="Lademeldung", interactive=False)
|
| 26 |
-
|
| 27 |
-
gr.Examples(
|
| 28 |
-
examples=["shiny-platypus-699", "delightful-red-panda-273", "glowing-toucan-982", "mellow-toucan-512", "upbeat-elephant-433"],
|
| 29 |
-
inputs=chatbot_id_input,
|
| 30 |
-
label="Beispiel-Chatbots"
|
| 31 |
-
)
|
| 32 |
|
| 33 |
with gr.Tabs():
|
| 34 |
with gr.Tab("Chat"):
|
| 35 |
-
chat_tab = create_chat_tab(
|
| 36 |
|
| 37 |
with gr.Tab("Chatbot erstellen"):
|
| 38 |
create_tab = create_chatbot_tab()
|
|
@@ -40,7 +31,7 @@ def create_app():
|
|
| 40 |
with gr.Tab("Admin"):
|
| 41 |
create_admin_tab()
|
| 42 |
|
| 43 |
-
@
|
| 44 |
def load_chatbot_on_start(chatbot_id, request: gr.Request):
|
| 45 |
params = request.query_params
|
| 46 |
if "chatbot_id" in params:
|
|
@@ -57,12 +48,12 @@ def create_app():
|
|
| 57 |
create_tab["chatbot_id_output"].change(
|
| 58 |
fn=load_chatbot,
|
| 59 |
inputs=[create_tab["chatbot_id_output"]],
|
| 60 |
-
outputs=[chat_tab['title'], chatbot_id_input, chat_tab['share_link'], load_message]
|
| 61 |
)
|
| 62 |
|
| 63 |
-
return
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|
| 68 |
-
|
|
|
|
| 18 |
}
|
| 19 |
</script>
|
| 20 |
"""
|
| 21 |
+
) as app:
|
| 22 |
gr.Markdown("# codora KI-App-Ersteller v0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
with gr.Tabs():
|
| 25 |
with gr.Tab("Chat"):
|
| 26 |
+
chat_tab = create_chat_tab()
|
| 27 |
|
| 28 |
with gr.Tab("Chatbot erstellen"):
|
| 29 |
create_tab = create_chatbot_tab()
|
|
|
|
| 31 |
with gr.Tab("Admin"):
|
| 32 |
create_admin_tab()
|
| 33 |
|
| 34 |
+
@app.load(inputs=[chat_tab['chatbot_id_input']], outputs=[chat_tab['title'], chat_tab['chatbot_id_input'], chat_tab['share_link'], chat_tab['load_message']])
|
| 35 |
def load_chatbot_on_start(chatbot_id, request: gr.Request):
|
| 36 |
params = request.query_params
|
| 37 |
if "chatbot_id" in params:
|
|
|
|
| 48 |
create_tab["chatbot_id_output"].change(
|
| 49 |
fn=load_chatbot,
|
| 50 |
inputs=[create_tab["chatbot_id_output"]],
|
| 51 |
+
outputs=[chat_tab['title'], chat_tab['chatbot_id_input'], chat_tab['share_link'], chat_tab['load_message']]
|
| 52 |
)
|
| 53 |
|
| 54 |
+
return app
|
| 55 |
|
| 56 |
+
app = create_app()
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
+
app.launch()
|
tabs/chat.py
CHANGED
|
@@ -17,7 +17,19 @@ def load_chatbot(chatbot_id):
|
|
| 17 |
gr.update(value="Ungültige Chatbot-ID oder Chatbot nicht aktiv.")
|
| 18 |
)
|
| 19 |
|
| 20 |
-
def create_chat_tab(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
chatbot_title = gr.Markdown("# Chatbot\n\nWillkommen beim Chatbot")
|
| 22 |
chat_interface = gr.ChatInterface(
|
| 23 |
chat_with_bot,
|
|
@@ -31,16 +43,20 @@ def create_chat_tab(chatbot_id_input, load_button, load_message):
|
|
| 31 |
outputs=[chatbot_title, chatbot_id_input, share_link, load_message]
|
| 32 |
)
|
| 33 |
|
| 34 |
-
#
|
| 35 |
copy_button = gr.HTML("""
|
| 36 |
-
<button onclick="copyToClipboard()">In die Zwischenablage kopieren</button>
|
| 37 |
""")
|
| 38 |
|
| 39 |
return {
|
|
|
|
|
|
|
|
|
|
| 40 |
"title": chatbot_title,
|
| 41 |
"interface": chat_interface,
|
| 42 |
"share_link": share_link,
|
| 43 |
-
"copy_button": copy_button
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
def chat_with_bot(message, history, chatbot_id):
|
|
|
|
| 17 |
gr.update(value="Ungültige Chatbot-ID oder Chatbot nicht aktiv.")
|
| 18 |
)
|
| 19 |
|
| 20 |
+
def create_chat_tab():
|
| 21 |
+
chatbot_id_input = gr.Textbox(label="Chatbot-ID eingeben")
|
| 22 |
+
|
| 23 |
+
# Add examples right below the chatbot ID input field
|
| 24 |
+
examples = gr.Examples(
|
| 25 |
+
examples=["shiny-platypus-699", "delightful-red-panda-273", "glowing-toucan-982", "mellow-toucan-512", "upbeat-elephant-433"],
|
| 26 |
+
inputs=chatbot_id_input,
|
| 27 |
+
label="Beispiel-Chatbots"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
load_button = gr.Button("Chatbot laden")
|
| 31 |
+
load_message = gr.Textbox(label="Lademeldung", interactive=False)
|
| 32 |
+
|
| 33 |
chatbot_title = gr.Markdown("# Chatbot\n\nWillkommen beim Chatbot")
|
| 34 |
chat_interface = gr.ChatInterface(
|
| 35 |
chat_with_bot,
|
|
|
|
| 43 |
outputs=[chatbot_title, chatbot_id_input, share_link, load_message]
|
| 44 |
)
|
| 45 |
|
| 46 |
+
# Add a custom HTML button for copying the share URL to the clipboard
|
| 47 |
copy_button = gr.HTML("""
|
| 48 |
+
<button onclick="copyToClipboard('share_link')">In die Zwischenablage kopieren</button>
|
| 49 |
""")
|
| 50 |
|
| 51 |
return {
|
| 52 |
+
"chatbot_id_input": chatbot_id_input,
|
| 53 |
+
"load_button": load_button,
|
| 54 |
+
"load_message": load_message,
|
| 55 |
"title": chatbot_title,
|
| 56 |
"interface": chat_interface,
|
| 57 |
"share_link": share_link,
|
| 58 |
+
"copy_button": copy_button,
|
| 59 |
+
"examples": examples
|
| 60 |
}
|
| 61 |
|
| 62 |
def chat_with_bot(message, history, chatbot_id):
|