Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Tobias Geisler
commited on
Commit
·
9e991a9
1
Parent(s):
5d557f1
Translation to German
Browse files- app.py +9 -9
- tabs/admin.py +18 -18
- tabs/chat.py +8 -8
- tabs/create_chatbot.py +8 -8
- 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
|
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("
|
15 |
}, function(err) {
|
16 |
-
console.error("
|
17 |
});
|
18 |
}
|
19 |
</script>
|
20 |
"""
|
21 |
) as demo:
|
22 |
-
gr.Markdown("# codora
|
23 |
-
chatbot_id_input = gr.Textbox(label="
|
24 |
-
load_button = gr.Button("
|
25 |
-
load_message = gr.Textbox(label="
|
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("
|
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="
|
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 "
|
10 |
|
11 |
chatbots = get_all_chatbots()
|
12 |
return gr.Dataframe(
|
13 |
-
headers=["ID", "Name", "
|
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 "
|
20 |
|
21 |
-
if action == "
|
22 |
update_chatbot(chatbot_id, name, custom_instruction, is_active)
|
23 |
-
return "Chatbot
|
24 |
-
elif action == "
|
25 |
delete_chatbot(chatbot_id)
|
26 |
-
return "Chatbot
|
27 |
else:
|
28 |
-
return "
|
29 |
|
30 |
def create_admin_tab():
|
31 |
-
admin_password = gr.Textbox(label="Admin
|
32 |
-
admin_button = gr.Button("
|
33 |
-
admin_output = gr.Dataframe(headers=["ID", "Name", "
|
34 |
admin_button.click(admin_view, inputs=[admin_password], outputs=admin_output)
|
35 |
|
36 |
with gr.Row():
|
37 |
-
admin_action_dropdown = gr.Dropdown(["
|
38 |
-
admin_chatbot_id = gr.Textbox(label="Chatbot
|
39 |
admin_name = gr.Textbox(label="Name")
|
40 |
-
admin_instruction = gr.Textbox(label="
|
41 |
-
admin_is_active = gr.Checkbox(label="
|
42 |
-
admin_action_button = gr.Button("
|
43 |
-
admin_action_output = gr.Textbox(label="
|
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"
|
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
|
12 |
)
|
13 |
return (
|
14 |
-
gr.update(value="
|
15 |
gr.update(value="", visible=True),
|
16 |
gr.update(value=""),
|
17 |
-
gr.update(value="
|
18 |
)
|
19 |
|
20 |
def create_chat_tab(chatbot_id_input, load_button, load_message):
|
21 |
-
chatbot_title = gr.Markdown("
|
22 |
chat_interface = gr.ChatInterface(
|
23 |
chat_with_bot,
|
24 |
additional_inputs=[chatbot_id_input],
|
25 |
)
|
26 |
-
share_link = gr.Textbox(label="
|
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 |
-
#
|
35 |
copy_button = gr.HTML("""
|
36 |
-
<button onclick="copyToClipboard()">
|
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 "
|
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
|
16 |
|
17 |
def create_chatbot_tab():
|
18 |
-
name = gr.Textbox(label="Chatbot
|
19 |
-
instructions = gr.Textbox(label="
|
20 |
-
create_password = gr.Textbox(label="
|
21 |
-
create_button = gr.Button("
|
22 |
-
create_output = gr.Textbox(label="
|
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 "
|
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"
|
|
|
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)}"
|