Spaces:
Build error
Build error
| import gradio as gr | |
| from utils.utils import get_secret | |
| from database import get_all_chatbots, update_chatbot, delete_chatbot | |
| ADMIN_PW = get_secret("ADMIN_PW") | |
| def admin_view(password): | |
| if password != ADMIN_PW: | |
| return "Ungültiges Admin-Passwort." | |
| chatbots = get_all_chatbots() | |
| return gr.Dataframe( | |
| headers=["ID", "Name", "Benutzerdefinierte Anweisung", "Ist aktiv"], | |
| data=[[c.chatbot_id, c.name, c.custom_instruction, c.is_active] for c in chatbots] | |
| ) | |
| def admin_action(action, chatbot_id, name, custom_instruction, is_active, password): | |
| if password != ADMIN_PW: | |
| return "Ungültiges Admin-Passwort." | |
| if action == "Bearbeiten": | |
| update_chatbot(chatbot_id, name, custom_instruction, is_active) | |
| return "Chatbot erfolgreich aktualisiert." | |
| elif action == "Löschen": | |
| delete_chatbot(chatbot_id) | |
| return "Chatbot erfolgreich gelöscht." | |
| else: | |
| return "Ungültige Aktion." | |
| def create_admin_tab(): | |
| admin_password = gr.Textbox(label="Admin-Passwort", type="password") | |
| admin_button = gr.Button("Chatbots anzeigen") | |
| admin_output = gr.Dataframe(headers=["ID", "Name", "Benutzerdefinierte Anweisung", "Ist aktiv"]) | |
| admin_button.click(admin_view, inputs=[admin_password], outputs=admin_output) | |
| with gr.Row(): | |
| admin_action_dropdown = gr.Dropdown(["Bearbeiten", "Löschen"], label="Aktion") | |
| admin_chatbot_id = gr.Textbox(label="Chatbot-ID") | |
| admin_name = gr.Textbox(label="Name") | |
| admin_instruction = gr.Textbox(label="Benutzerdefinierte Anweisung") | |
| admin_is_active = gr.Checkbox(label="Ist aktiv") | |
| admin_action_button = gr.Button("Aktion ausführen") | |
| admin_action_output = gr.Textbox(label="Ergebnis der Aktion") | |
| admin_action_button.click( | |
| admin_action, | |
| inputs=[admin_action_dropdown, admin_chatbot_id, admin_name, admin_instruction, admin_is_active, admin_password], | |
| outputs=admin_action_output | |
| ) | |