Tobias Geisler commited on
Commit
6ba3c65
·
1 Parent(s): d5c95b9

better chatbot creation flow

Browse files
Files changed (2) hide show
  1. app.py +14 -7
  2. tabs/create_chatbot.py +32 -8
app.py CHANGED
@@ -5,15 +5,15 @@ from tabs.admin import create_admin_tab
5
 
6
  def create_app():
7
  with gr.Blocks(
8
- title="codora KI-App-Creator v0",
9
  head="""
10
  <script>
11
- function copyToClipboard() {
12
- var copyText = document.querySelector("#share_link textarea").value;
13
  navigator.clipboard.writeText(copyText).then(function() {
14
- alert("Link kopiert: " + copyText);
15
  }, function(err) {
16
- console.error("Konnte Link nicht kopieren: ", err);
17
  });
18
  }
19
  </script>
@@ -23,7 +23,7 @@ def create_app():
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,
@@ -35,7 +35,7 @@ def create_app():
35
  chat_tab = create_chat_tab(chatbot_id_input, load_button, load_message)
36
 
37
  with gr.Tab("Chatbot erstellen"):
38
- create_chatbot_tab()
39
 
40
  with gr.Tab("Admin"):
41
  create_admin_tab()
@@ -53,6 +53,13 @@ def create_app():
53
  gr.update(value="")
54
  )
55
 
 
 
 
 
 
 
 
56
  return demo
57
 
58
  demo = create_app()
 
5
 
6
  def create_app():
7
  with gr.Blocks(
8
+ title="codora KI-App-Ersteller v0",
9
  head="""
10
  <script>
11
+ function copyToClipboard(elementId) {
12
+ var copyText = document.getElementById(elementId).querySelector('textarea').value;
13
  navigator.clipboard.writeText(copyText).then(function() {
14
+ alert("Text kopiert: " + copyText);
15
  }, function(err) {
16
+ console.error("Konnte Text nicht kopieren: ", err);
17
  });
18
  }
19
  </script>
 
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,
 
35
  chat_tab = create_chat_tab(chatbot_id_input, load_button, load_message)
36
 
37
  with gr.Tab("Chatbot erstellen"):
38
+ create_tab = create_chatbot_tab()
39
 
40
  with gr.Tab("Admin"):
41
  create_admin_tab()
 
53
  gr.update(value="")
54
  )
55
 
56
+ # Add event listener to automatically load newly created chatbot
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 demo
64
 
65
  demo = create_app()
tabs/create_chatbot.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import gradio as gr
2
  from utils.utils import get_secret
3
  from database import create_chatbot, filter_profanity
@@ -6,18 +8,40 @@ CREATE_APP_PW = get_secret("CREATE_APP_PW")
6
 
7
  def create_chatbot_interface(name, custom_instruction, password):
8
  if password != CREATE_APP_PW:
9
- return "Ungültiges Passwort. Erstellung des Chatbots fehlgeschlagen."
10
 
11
  filtered_name = filter_profanity(name)
12
  filtered_instruction = filter_profanity(custom_instruction)
13
 
14
  chatbot = create_chatbot(filtered_name, filtered_instruction)
15
- return f"Chatbot erstellt mit ID: {chatbot.chatbot_id}"
16
 
17
  def create_chatbot_tab():
18
- name = gr.Textbox(label="Chatbot-Name")
19
- instructions = gr.Textbox(label="Benutzerdefinierte Anweisungen für Ihren Chatbot eingeben")
20
- create_password = gr.Textbox(label="Erstellungspasswort", type="password")
21
- create_button = gr.Button("Chatbot erstellen")
22
- create_output = gr.Textbox(label="Ergebnis der Erstellung")
23
- create_button.click(create_chatbot_interface, inputs=[name, instructions, create_password], outputs=create_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # In create_chatbot.py
2
+
3
  import gradio as gr
4
  from utils.utils import get_secret
5
  from database import create_chatbot, filter_profanity
 
8
 
9
  def create_chatbot_interface(name, custom_instruction, password):
10
  if password != CREATE_APP_PW:
11
+ return "Ungültiges Passwort. Erstellung des Chatbots fehlgeschlagen.", None, None
12
 
13
  filtered_name = filter_profanity(name)
14
  filtered_instruction = filter_profanity(custom_instruction)
15
 
16
  chatbot = create_chatbot(filtered_name, filtered_instruction)
17
+ return f"Chatbot erstellt mit ID: {chatbot.chatbot_id}", chatbot.chatbot_id, chatbot.name
18
 
19
  def create_chatbot_tab():
20
+ with gr.Group():
21
+ name = gr.Textbox(label="Chatbot-Name")
22
+ instructions = gr.Textbox(label="Benutzerdefinierte Anweisungen für Ihren Chatbot eingeben", lines=6) # Changed to 6 lines
23
+ create_password = gr.Textbox(label="Erstellungspasswort", type="password")
24
+ create_button = gr.Button("Chatbot erstellen")
25
+ create_output = gr.Textbox(label="Ergebnis der Erstellung")
26
+ chatbot_id_output = gr.Textbox(label="Erstellte Chatbot-ID", elem_id="created_chatbot_id")
27
+ chatbot_name_output = gr.Textbox(label="Erstellter Chatbot-Name", elem_id="created_chatbot_name")
28
+
29
+ # Add copy buttons
30
+ copy_id_button = gr.HTML("""
31
+ <button onclick="copyToClipboard('created_chatbot_id')">Chatbot-ID kopieren</button>
32
+ """)
33
+ copy_name_button = gr.HTML("""
34
+ <button onclick="copyToClipboard('created_chatbot_name')">Chatbot-Name kopieren</button>
35
+ """)
36
+
37
+ create_button.click(
38
+ create_chatbot_interface,
39
+ inputs=[name, instructions, create_password],
40
+ outputs=[create_output, chatbot_id_output, chatbot_name_output]
41
+ )
42
+
43
+ return {
44
+ "create_output": create_output,
45
+ "chatbot_id_output": chatbot_id_output,
46
+ "chatbot_name_output": chatbot_name_output
47
+ }