import gradio as gr # Define some pre-written templates for Tab 1 templates = { "Friendly Chatbot": "You are a helpful, friendly chatbot that engages in light-hearted conversations.", "Technical Assistant": "You are a technical assistant specialized in answering questions related to Python programming.", "Nutrition Advisor": "You provide evidence-based advice on nutrition and healthy eating habits.", } # Define some agentic workflows for Tab 2 agentic_workflows = { "Blog Post Generator": "This agent is designed to help generate a blog post based on user input.", "Document Summarizer": "This agent summarizes long documents by extracting key points.", "Task Manager": "This agent helps you organize tasks and provides step-by-step guidance." } # Chatbot logic for custom instructions or pre-written templates def chatbot_response(system_instructions, user_query): if "friendly" in system_instructions.lower(): return f"Friendly Chatbot says: Hi there! 😊 How can I assist you today?" elif "technical" in system_instructions.lower(): return f"Technical Assistant says: Sure! Here's some information on Python: {user_query}" elif "nutrition" in system_instructions.lower(): return f"Nutrition Advisor says: Here's some advice about healthy eating: {user_query}" else: return f"Custom Chatbot says: {user_query}" # Chatbot conversation function def chatbot_conversation(system_instructions, chat_history, user_query): response = chatbot_response(system_instructions, user_query) chat_history.append((user_query, response)) return chat_history, "" # Chatbot conversation for predefined agentic workflows def agentic_chatbot_conversation(workflow_instructions, chat_history, user_query): response = f"Agent Workflow ({workflow_instructions}) says: {user_query}" chat_history.append((user_query, response)) return chat_history, "" # Function to update the interface when a selection is made from the dropdown (Tab 1) def update_interface(template_name, custom_instructions): if template_name == "Custom Instructions": return gr.update(visible=True), gr.update(visible=False) else: template_content = templates.get(template_name, "") return gr.update(visible=False), gr.update(visible=True, value=template_content) # Build the Gradio interface with Tabs with gr.Blocks(css=".gradio-container {background-color: #F0F0F0;} .gr-button {background-color: #1E3A8A; color: white;} .gr-textbox textarea {font-size: 16px;} .gr-markdown {font-size: 18px; color: #1E3A8A;}") as demo: # Add Tabs with gr.Tabs(): # Tab 1: Custom Instructions or Pre-Written Templates with gr.Tab("Custom Instructions Chatbot"): gr.Markdown("""
This tool allows you to experiment with different system prompts, giving you control over how the chatbot behaves. You can either use pre-defined templates or write your own custom instructions.
Explore predefined agentic workflows that execute specific tasks, such as generating blog posts, summarizing documents, or managing tasks.