Tobias Geisler commited on
Commit
9e991a9
·
1 Parent(s): 5d557f1

Translation to German

Browse files
Files changed (5) hide show
  1. app.py +9 -9
  2. tabs/admin.py +18 -18
  3. tabs/chat.py +8 -8
  4. tabs/create_chatbot.py +8 -8
  5. utils/openai_utils.py +2 -2
app.py CHANGED
@@ -5,30 +5,30 @@ from tabs.admin import create_admin_tab
5
 
6
  def create_app():
7
  with gr.Blocks(
8
- title="codora AI 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("Copied the text: " + copyText);
15
  }, function(err) {
16
- console.error("Could not copy text: ", err);
17
  });
18
  }
19
  </script>
20
  """
21
  ) as demo:
22
- gr.Markdown("# codora AI App Creator v0")
23
- chatbot_id_input = gr.Textbox(label="Enter Chatbot ID")
24
- load_button = gr.Button("Load Chatbot")
25
- load_message = gr.Textbox(label="Load Message", interactive=False)
26
 
27
  with gr.Tabs():
28
  with gr.Tab("Chat"):
29
  chat_tab = create_chat_tab(chatbot_id_input, load_button, load_message)
30
 
31
- with gr.Tab("Create Chatbot"):
32
  create_chatbot_tab()
33
 
34
  with gr.Tab("Admin"):
@@ -41,7 +41,7 @@ def create_app():
41
  chatbot_id = params["chatbot_id"]
42
  return load_chatbot(chatbot_id)
43
  return (
44
- gr.update(value="Welcome to the Chatbot"),
45
  gr.update(value="", visible=True),
46
  gr.update(value=""),
47
  gr.update(value="")
 
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>
20
  """
21
  ) as demo:
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
  with gr.Tabs():
28
  with gr.Tab("Chat"):
29
  chat_tab = create_chat_tab(chatbot_id_input, load_button, load_message)
30
 
31
+ with gr.Tab("Chatbot erstellen"):
32
  create_chatbot_tab()
33
 
34
  with gr.Tab("Admin"):
 
41
  chatbot_id = params["chatbot_id"]
42
  return load_chatbot(chatbot_id)
43
  return (
44
+ gr.update(value="Willkommen beim Chatbot"),
45
  gr.update(value="", visible=True),
46
  gr.update(value=""),
47
  gr.update(value="")
tabs/admin.py CHANGED
@@ -6,43 +6,43 @@ ADMIN_PW = get_secret("ADMIN_PW")
6
 
7
  def admin_view(password):
8
  if password != ADMIN_PW:
9
- return "Invalid admin password."
10
 
11
  chatbots = get_all_chatbots()
12
  return gr.Dataframe(
13
- headers=["ID", "Name", "Custom Instruction", "Is Active"],
14
  data=[[c.chatbot_id, c.name, c.custom_instruction, c.is_active] for c in chatbots]
15
  )
16
 
17
  def admin_action(action, chatbot_id, name, custom_instruction, is_active, password):
18
  if password != ADMIN_PW:
19
- return "Invalid admin password."
20
 
21
- if action == "Edit":
22
  update_chatbot(chatbot_id, name, custom_instruction, is_active)
23
- return "Chatbot updated successfully."
24
- elif action == "Delete":
25
  delete_chatbot(chatbot_id)
26
- return "Chatbot deleted successfully."
27
  else:
28
- return "Invalid action."
29
 
30
  def create_admin_tab():
31
- admin_password = gr.Textbox(label="Admin Password", type="password")
32
- admin_button = gr.Button("View Chatbots")
33
- admin_output = gr.Dataframe(headers=["ID", "Name", "Custom Instruction", "Is Active"])
34
  admin_button.click(admin_view, inputs=[admin_password], outputs=admin_output)
35
 
36
  with gr.Row():
37
- admin_action_dropdown = gr.Dropdown(["Edit", "Delete"], label="Action")
38
- admin_chatbot_id = gr.Textbox(label="Chatbot ID")
39
  admin_name = gr.Textbox(label="Name")
40
- admin_instruction = gr.Textbox(label="Custom Instruction")
41
- admin_is_active = gr.Checkbox(label="Is Active")
42
- admin_action_button = gr.Button("Perform Action")
43
- admin_action_output = gr.Textbox(label="Action Result")
44
  admin_action_button.click(
45
  admin_action,
46
  inputs=[admin_action_dropdown, admin_chatbot_id, admin_name, admin_instruction, admin_is_active, admin_password],
47
  outputs=admin_action_output
48
- )
 
6
 
7
  def admin_view(password):
8
  if password != ADMIN_PW:
9
+ return "Ungültiges Admin-Passwort."
10
 
11
  chatbots = get_all_chatbots()
12
  return gr.Dataframe(
13
+ headers=["ID", "Name", "Benutzerdefinierte Anweisung", "Ist aktiv"],
14
  data=[[c.chatbot_id, c.name, c.custom_instruction, c.is_active] for c in chatbots]
15
  )
16
 
17
  def admin_action(action, chatbot_id, name, custom_instruction, is_active, password):
18
  if password != ADMIN_PW:
19
+ return "Ungültiges Admin-Passwort."
20
 
21
+ if action == "Bearbeiten":
22
  update_chatbot(chatbot_id, name, custom_instruction, is_active)
23
+ return "Chatbot erfolgreich aktualisiert."
24
+ elif action == "Löschen":
25
  delete_chatbot(chatbot_id)
26
+ return "Chatbot erfolgreich gelöscht."
27
  else:
28
+ return "Ungültige Aktion."
29
 
30
  def create_admin_tab():
31
+ admin_password = gr.Textbox(label="Admin-Passwort", type="password")
32
+ admin_button = gr.Button("Chatbots anzeigen")
33
+ admin_output = gr.Dataframe(headers=["ID", "Name", "Benutzerdefinierte Anweisung", "Ist aktiv"])
34
  admin_button.click(admin_view, inputs=[admin_password], outputs=admin_output)
35
 
36
  with gr.Row():
37
+ admin_action_dropdown = gr.Dropdown(["Bearbeiten", "Löschen"], label="Aktion")
38
+ admin_chatbot_id = gr.Textbox(label="Chatbot-ID")
39
  admin_name = gr.Textbox(label="Name")
40
+ admin_instruction = gr.Textbox(label="Benutzerdefinierte Anweisung")
41
+ admin_is_active = gr.Checkbox(label="Ist aktiv")
42
+ admin_action_button = gr.Button("Aktion ausführen")
43
+ admin_action_output = gr.Textbox(label="Ergebnis der Aktion")
44
  admin_action_button.click(
45
  admin_action,
46
  inputs=[admin_action_dropdown, admin_chatbot_id, admin_name, admin_instruction, admin_is_active, admin_password],
47
  outputs=admin_action_output
48
+ )
tabs/chat.py CHANGED
@@ -5,25 +5,25 @@ def load_chatbot(chatbot_id):
5
  chatbot = get_chatbot(chatbot_id)
6
  if chatbot:
7
  return (
8
- gr.update(value=f"Welcome to {chatbot.name}"),
9
  gr.update(value=chatbot_id, visible=True),
10
  gr.update(value=f"https://huggingface.co/spaces/codora/ai-app-creator?chatbot_id={chatbot_id}"),
11
- gr.update(value="Chatbot loaded successfully.")
12
  )
13
  return (
14
- gr.update(value="Welcome to the Chatbot"),
15
  gr.update(value="", visible=True),
16
  gr.update(value=""),
17
- gr.update(value="Invalid chatbot ID or chatbot not active.")
18
  )
19
 
20
  def create_chat_tab(chatbot_id_input, load_button, load_message):
21
- chatbot_title = gr.Markdown("Welcome to the Chatbot")
22
  chat_interface = gr.ChatInterface(
23
  chat_with_bot,
24
  additional_inputs=[chatbot_id_input],
25
  )
26
- share_link = gr.Textbox(label="Share Link", interactive=False, elem_id="share_link")
27
 
28
  load_button.click(
29
  fn=load_chatbot,
@@ -31,9 +31,9 @@ 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
- # Add a custom HTML button for copying the share URL to the clipboard
35
  copy_button = gr.HTML("""
36
- <button onclick="copyToClipboard()">Copy to Clipboard</button>
37
  """)
38
 
39
  return {
 
5
  chatbot = get_chatbot(chatbot_id)
6
  if chatbot:
7
  return (
8
+ gr.update(value=f"Willkommen bei {chatbot.name}"),
9
  gr.update(value=chatbot_id, visible=True),
10
  gr.update(value=f"https://huggingface.co/spaces/codora/ai-app-creator?chatbot_id={chatbot_id}"),
11
+ gr.update(value="Chatbot erfolgreich geladen.")
12
  )
13
  return (
14
+ gr.update(value="Willkommen beim Chatbot"),
15
  gr.update(value="", visible=True),
16
  gr.update(value=""),
17
+ gr.update(value="Ungültige Chatbot-ID oder Chatbot nicht aktiv.")
18
  )
19
 
20
  def create_chat_tab(chatbot_id_input, load_button, load_message):
21
+ chatbot_title = gr.Markdown("Willkommen beim Chatbot")
22
  chat_interface = gr.ChatInterface(
23
  chat_with_bot,
24
  additional_inputs=[chatbot_id_input],
25
  )
26
+ share_link = gr.Textbox(label="Link zum Teilen", interactive=False, elem_id="share_link")
27
 
28
  load_button.click(
29
  fn=load_chatbot,
 
31
  outputs=[chatbot_title, chatbot_id_input, share_link, load_message]
32
  )
33
 
34
+ # Fügen Sie eine benutzerdefinierte HTML-Schaltfläche hinzu, um die URL zum Teilen in die Zwischenablage zu kopieren
35
  copy_button = gr.HTML("""
36
+ <button onclick="copyToClipboard()">In die Zwischenablage kopieren</button>
37
  """)
38
 
39
  return {
tabs/create_chatbot.py CHANGED
@@ -6,18 +6,18 @@ 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 "Invalid password. Chatbot creation failed."
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 created with ID: {chatbot.chatbot_id}"
16
 
17
  def create_chatbot_tab():
18
- name = gr.Textbox(label="Chatbot Name")
19
- instructions = gr.Textbox(label="Enter custom instructions for your chatbot")
20
- create_password = gr.Textbox(label="Creation Password", type="password")
21
- create_button = gr.Button("Create Chatbot")
22
- create_output = gr.Textbox(label="Creation Result")
23
- create_button.click(create_chatbot_interface, inputs=[name, instructions, create_password], outputs=create_output)
 
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)
utils/openai_utils.py CHANGED
@@ -8,7 +8,7 @@ def chat_with_bot(message, history, chatbot_id):
8
  from database import get_chatbot
9
  chatbot = get_chatbot(chatbot_id)
10
  if not chatbot:
11
- return "Invalid chatbot ID or chatbot not active"
12
 
13
  conversation = [
14
  {"role": "system", "content": chatbot.custom_instruction},
@@ -23,4 +23,4 @@ def chat_with_bot(message, history, chatbot_id):
23
  messages=conversation)
24
  return response.choices[0].message.content
25
  except Exception as e:
26
- return f"An error occurred: {str(e)}"
 
8
  from database import get_chatbot
9
  chatbot = get_chatbot(chatbot_id)
10
  if not chatbot:
11
+ return "Ungültige Chatbot-ID oder Chatbot nicht aktiv"
12
 
13
  conversation = [
14
  {"role": "system", "content": chatbot.custom_instruction},
 
23
  messages=conversation)
24
  return response.choices[0].message.content
25
  except Exception as e:
26
+ return f"Ein Fehler ist aufgetreten: {str(e)}"