Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,294 Bytes
c91ccb6 71736e8 7db7d27 c91ccb6 7db7d27 71736e8 c91ccb6 71736e8 c91ccb6 6ba3c65 71736e8 7db7d27 c91ccb6 7db7d27 c91ccb6 71736e8 6ba3c65 |
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 |
# create_chatbot.py
import gradio as gr
from utils.utils import get_secret
from database import create_chatbot, filter_profanity
import logging
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
CREATE_APP_PW = get_secret("CREATE_APP_PW")
def create_chatbot_interface(name, custom_instruction, password):
logger.info("Creating chatbot with name: %s", name)
if password != CREATE_APP_PW:
logger.warning("Invalid password provided for chatbot creation.")
return "Ungültiges Passwort. Erstellung des Chatbots fehlgeschlagen.", None, None
filtered_name = filter_profanity(name)
filtered_instruction = filter_profanity(custom_instruction)
try:
chatbot = create_chatbot(filtered_name, filtered_instruction)
logger.info("Chatbot created successfully with ID: %s", chatbot.chatbot_id)
return f"Chatbot erstellt mit ID: {chatbot.chatbot_id}", chatbot.chatbot_id, chatbot.name
except Exception as e:
logger.error("Error creating chatbot: %s", str(e))
return f"Fehler bei der Erstellung des Chatbots: {str(e)}", None, None
def create_chatbot_tab():
with gr.Group():
name = gr.Textbox(label="Chatbot-Name")
instructions = gr.Textbox(label="Benutzerdefinierte Anweisungen für Ihren Chatbot eingeben", lines=6) # Changed to 6 lines
create_password = gr.Textbox(label="Erstellungspasswort", type="password")
create_button = gr.Button("Chatbot erstellen")
create_output = gr.Textbox(label="Ergebnis der Erstellung")
chatbot_id_output = gr.Textbox(label="Erstellte Chatbot-ID", elem_id="created_chatbot_id")
chatbot_name_output = gr.Textbox(label="Erstellter Chatbot-Name", elem_id="created_chatbot_name")
# Add copy buttons
copy_id_button = gr.HTML("""
<button onclick="copyToClipboard('created_chatbot_id')">Chatbot-ID kopieren</button>
""")
create_button.click(
create_chatbot_interface,
inputs=[name, instructions, create_password],
outputs=[create_output, chatbot_id_output, chatbot_name_output]
)
return {
"create_output": create_output,
"chatbot_id_output": chatbot_id_output,
"chatbot_name_output": chatbot_name_output
}
|