ai-app-creator / tabs /admin.py
Tobias Geisler
refactor
71736e8
raw
history blame
1.92 kB
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 "Invalid admin password."
chatbots = get_all_chatbots()
return gr.Dataframe(
headers=["ID", "Name", "Custom Instruction", "Is Active"],
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 "Invalid admin password."
if action == "Edit":
update_chatbot(chatbot_id, name, custom_instruction, is_active)
return "Chatbot updated successfully."
elif action == "Delete":
delete_chatbot(chatbot_id)
return "Chatbot deleted successfully."
else:
return "Invalid action."
def create_admin_tab():
admin_password = gr.Textbox(label="Admin Password", type="password")
admin_button = gr.Button("View Chatbots")
admin_output = gr.Dataframe(headers=["ID", "Name", "Custom Instruction", "Is Active"])
admin_button.click(admin_view, inputs=[admin_password], outputs=admin_output)
with gr.Row():
admin_action_dropdown = gr.Dropdown(["Edit", "Delete"], label="Action")
admin_chatbot_id = gr.Textbox(label="Chatbot ID")
admin_name = gr.Textbox(label="Name")
admin_instruction = gr.Textbox(label="Custom Instruction")
admin_is_active = gr.Checkbox(label="Is Active")
admin_action_button = gr.Button("Perform Action")
admin_action_output = gr.Textbox(label="Action Result")
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
)