import streamlit as st import pandas as pd import random import json import os from datetime import datetime import base64 # Set page configuration st.set_page_config(page_title="PromptWizardry", page_icon="🧠", layout="wide") # Custom CSS for styling st.markdown(""" """, unsafe_allow_html=True) # Initialize session state with default topic if 'selections' not in st.session_state: st.session_state.selections = { 'role': None, 'tone': None, 'instruction': None, 'length': None, 'content_type': None, 'audience': None, 'format': None, 'about': "DistillKit, MergeKit, Spectrum for ML Model Building from input Spreadsheets using torch, transformers and Streamlit", 'inclusion': "", 'exclusion': "", 'input_data': "" } if 'prompt_history' not in st.session_state: st.session_state.prompt_history = [] # Data sets with emoji and names data = { 'roles': [ {"name": "Professional", "emoji": "👔"}, {"name": "Expert", "emoji": "🧠"}, {"name": "Friend", "emoji": "🤝"}, {"name": "Copywriter", "emoji": "✍ī¸"}, {"name": "Creative Writer", "emoji": "🖋ī¸"}, {"name": "Sales Coach", "emoji": "đŸ’ŧ"}, {"name": "Marketing Coach", "emoji": "📊"}, {"name": "Tech Consultant", "emoji": "đŸ’ģ"}, {"name": "Life Coach", "emoji": "🧘"}, {"name": "Data Analyst", "emoji": "📈"}, {"name": "Influencer", "emoji": "📱"}, {"name": "Language Tutor", "emoji": "đŸ—Ŗī¸"}, {"name": "Fitness Trainer", "emoji": "đŸ’Ē"}, {"name": "Teacher", "emoji": "👨‍đŸĢ"}, {"name": "Therapist", "emoji": "🧐"}, {"name": "Detective", "emoji": "🔍"} ], 'tones': [ {"name": "Informative", "emoji": "ℹī¸"}, {"name": "Inspirational", "emoji": "✨"}, {"name": "Humorous", "emoji": "😄"}, {"name": "Friendly", "emoji": "😊"}, {"name": "Professional", "emoji": "👔"}, {"name": "Casual", "emoji": "👋"}, {"name": "Persuasive", "emoji": "🤝"}, {"name": "Encouraging", "emoji": "🙌"}, {"name": "Empathetic", "emoji": "🤗"}, {"name": "Serious", "emoji": "😐"}, {"name": "Enthusiastic", "emoji": "🤩"}, {"name": "Thoughtful", "emoji": "💭"} ], 'instructions': [ {"name": "Create", "emoji": "🔨"}, {"name": "Suggest", "emoji": "💡"}, {"name": "Write", "emoji": "✍ī¸"}, {"name": "Compose", "emoji": "📝"}, {"name": "Analyze", "emoji": "🔍"}, {"name": "Explain", "emoji": "📚"}, {"name": "Describe", "emoji": "🔎"}, {"name": "Summarize", "emoji": "📋"}, {"name": "Compare", "emoji": "⚖ī¸"}, {"name": "Outline", "emoji": "📋"}, {"name": "Evaluate", "emoji": "⭐"}, {"name": "List", "emoji": "📋"} ], 'lengths': [ {"name": "300 Words", "emoji": "📝"}, {"name": "500 Words", "emoji": "📄"}, {"name": "Short", "emoji": "đŸŠŗ"}, {"name": "Medium", "emoji": "📊"}, {"name": "Long", "emoji": "📜"}, {"name": "Brief", "emoji": "💨"}, {"name": "Detailed", "emoji": "🔎"}, {"name": "Comprehensive", "emoji": "📚"} ], 'content_types': [ {"name": "Article", "emoji": "📰"}, {"name": "Blog post", "emoji": "📝"}, {"name": "Guide", "emoji": "📚"}, {"name": "Email", "emoji": "📧"}, {"name": "Summary", "emoji": "📋"}, {"name": "Story", "emoji": "📖"}, {"name": "Essay", "emoji": "📄"}, {"name": "Review", "emoji": "⭐"}, {"name": "Tutorial", "emoji": "👨‍đŸĢ"}, {"name": "Report", "emoji": "📊"}, {"name": "Plan", "emoji": "📆"}, {"name": "Script", "emoji": "đŸŽŦ"} ], 'audiences': [ {"name": "Beginners", "emoji": "🌱"}, {"name": "Experts", "emoji": "🧠"}, {"name": "Students", "emoji": "🎓"}, {"name": "Professionals", "emoji": "👔"}, {"name": "Business Owners", "emoji": "đŸ’ŧ"}, {"name": "General Public", "emoji": "đŸ‘Ĩ"}, {"name": "Developers", "emoji": "đŸ’ģ"}, {"name": "Children", "emoji": "đŸ‘ļ"} ], 'formats': [ {"name": "Markdown", "emoji": "📝"}, {"name": "HTML", "emoji": "🌐"}, {"name": "Plain Text", "emoji": "📄"}, {"name": "JSON", "emoji": "🔄"}, {"name": "PDF", "emoji": "📑"}, {"name": "Python Code", "emoji": "🐍"}, {"name": "JavaScript", "emoji": "📜"}, {"name": "SQL Query", "emoji": "💾"}, {"name": "Image Gen Prompt", "emoji": "đŸ–ŧī¸"}, {"name": "Video Gen Prompt", "emoji": "đŸŽĨ"}, {"name": "Song Gen Prompt", "emoji": "đŸŽĩ"}, {"name": "Story Gen Prompt", "emoji": "📚"} ] } # Function to handle selection def handle_selection(category, item): st.session_state.selections[category] = item # Function to create category selection with buttons def create_dataframe_category(category, title, emoji_prefix): st.markdown(f"
{emoji_prefix} {title}
", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) cols = st.columns(4) for i, item in enumerate(data[f"{category}s"]): col = cols[i % 4] label = f"{item['emoji']} {item['name']}" is_selected = st.session_state.selections[category] == item with col: if st.button(label, key=f"{category}_{i}", type="primary" if is_selected else "secondary", use_container_width=True): handle_selection(category, item) st.markdown("
", unsafe_allow_html=True) # Function to generate the final prompt def generate_prompt(): sel = st.session_state.selections if not all([sel['role'], sel['tone'], sel['instruction'], sel['length'], sel['content_type'], sel['audience'], sel['format']]): return "Please select all required components." prompt = f"""Act as a {sel['role']['emoji']} {sel['role']['name']}, use {sel['tone']['emoji']} {sel['tone']['name']} tone, {sel['instruction']['emoji']} {sel['instruction']['name']} a {sel['length']['emoji']} {sel['length']['name']} {sel['content_type']['emoji']} {sel['content_type']['name']} for {sel['audience']['emoji']} {sel['audience']['name']}. It should be about {sel['about']}.""" if sel['inclusion']: prompt += f"\nInclude {sel['inclusion']}." if sel['exclusion']: prompt += f"\nExclude {sel['exclusion']}." prompt += f"\n\nReturn the output as {sel['format']['emoji']} {sel['format']['name']}." if sel['input_data']: prompt += f"\nUse the following information: {sel['input_data']}" return prompt # Function to save prompt as markdown file and return filename def save_prompt_as_md(prompt): sel = st.session_state.selections if not prompt.startswith("Please"): components = [ sel['role']['name'], sel['tone']['name'], sel['instruction']['name'], sel['length']['name'], sel['content_type']['name'], sel['audience']['name'], sel['format']['name'] ] timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") filename = f"prompt_{'_'.join(comp.lower().replace(' ', '_') for comp in components)}_{timestamp}.md" os.makedirs("prompts", exist_ok=True) with open(os.path.join("prompts", filename), "w") as f: f.write(f"```markdown\n{prompt}\n```") return filename return None # Function to get list of saved .md files def get_saved_md_files(): os.makedirs("prompts", exist_ok=True) return [f for f in os.listdir("prompts") if f.endswith(".md")] # Function to generate Base64 download link def get_base64_download_link(filepath): with open(filepath, "rb") as f: data = f.read() b64 = base64.b64encode(data).decode() filename = os.path.basename(filepath) return f'Download {filename}' # Sidebar with Saved Prompts and Feature Outline with st.sidebar: st.markdown("### 📁 Saved Prompts") md_files = get_saved_md_files() if md_files: for md_file in sorted(md_files, reverse=True): filepath = os.path.join("prompts", md_file) st.markdown(f"- {get_base64_download_link(filepath)}", unsafe_allow_html=True) else: st.write("No saved prompts yet.") st.markdown("### 🌟 PromptWizardry Magic") st.markdown(""" - 🌈 **Prompt Alchemy**: Craft with roles, tones, & more! - đŸĒ„ **Actions**: Copy, Reset, Random, Run! - 💾 **Scroll Vault**: Save & download `.md` spells! - âŗ **Chronicles**: Relive your magic history! - 🎉 **Extras**: Sample spells & dazzling UI! """) # Header st.markdown("

✨ PromptWizardry

", unsafe_allow_html=True) # Main layout with two columns col1, col2 = st.columns([3, 1]) with col1: create_dataframe_category("role", "Choose a Role", "👤") create_dataframe_category("tone", "Select a Tone", "🎭") create_dataframe_category("instruction", "Select an Instruction", "📝") create_dataframe_category("length", "Select Length", "📏") create_dataframe_category("content_type", "Select Content Type", "📄") create_dataframe_category("audience", "Select Target Audience", "đŸ‘Ĩ") create_dataframe_category("format", "Select Format", "📋") st.markdown("
📌 Additional Details
", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) st.session_state.selections['about'] = st.text_input("đŸ’Ŧ Topic", value=st.session_state.selections['about'], placeholder="Enter what the content should be about") include_exclude_cols = st.columns(2) with include_exclude_cols[0]: st.session_state.selections['inclusion'] = st.text_input("✅ Include", value=st.session_state.selections['inclusion'], placeholder="What to include in the content") with include_exclude_cols[1]: st.session_state.selections['exclusion'] = st.text_input("❌ Exclude", value=st.session_state.selections['exclusion'], placeholder="What to exclude from the content") st.session_state.selections['input_data'] = st.text_area("📊 Input Data", value=st.session_state.selections['input_data'], placeholder="Enter any specific information to use", height=100) st.markdown("
", unsafe_allow_html=True) with col2: prompt = generate_prompt() st.markdown("
🔮 Generated Prompt
", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) st.text_area("", value=prompt, height=150, key="generated_prompt", disabled=True, help="Your magical prompt appears here!") st.markdown("
", unsafe_allow_html=True) button_cols = st.columns(4) with button_cols[0]: if st.button("📋 Copy", type="secondary", use_container_width=True): st.code(prompt, language="") with button_cols[1]: if st.button("🔄 Reset", type="secondary", use_container_width=True): for key in st.session_state.selections: if key in ['about', 'inclusion', 'exclusion', 'input_data']: st.session_state.selections[key] = "" if key != 'about' else "DistillKit, MergeKit, Spectrum for ML Model Building from input Spreadsheets using torch, transformers and Streamlit" else: st.session_state.selections[key] = None st.session_state.prompt_history = [] st.rerun() with button_cols[2]: if st.button("🎲 Random", type="secondary", use_container_width=True): for category in ['role', 'tone', 'instruction', 'length', 'content_type', 'audience', 'format']: st.session_state.selections[category] = random.choice(data[category+'s']) st.rerun() with button_cols[3]: if st.button("🏃 Run", type="primary", use_container_width=True): if not prompt.startswith("Please"): st.code(f"```markdown\n{prompt}\n```", language="markdown") filename = save_prompt_as_md(prompt) if filename: st.success(f"Saved as {filename}") st.session_state.prompt_history.append({ "prompt": prompt, "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "filename": filename }) st.markdown("
📜 Live Prompt Code
", unsafe_allow_html=True) st.code(f"```markdown\n{prompt}\n```", language="markdown") st.markdown("", unsafe_allow_html=True) st.markdown("
📜 Prompt History
", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) if st.session_state.prompt_history: for i, entry in enumerate(reversed(st.session_state.prompt_history)): st.markdown(f"**Prompt {len(st.session_state.prompt_history) - i} ({entry['timestamp']})**") st.code(f"```markdown\n{entry['prompt']}\n```", language="markdown") st.write(f"Saved as: `{entry['filename']}`") else: st.write("No prompts generated yet.") st.markdown("
", unsafe_allow_html=True) st.markdown("
📚 Examples
", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) st.markdown("""
👨‍đŸĢ Teaching
Act as a 👨‍đŸĢ Teacher, use 📚 Informative tone, Create a 📋 Guide for 🌱 Beginners.

It should be about Git.
Include practical examples.
Exclude advanced techniques.

Return as 📝 Markdown.
""", unsafe_allow_html=True) st.markdown("""
đŸ’ŧ Business
Act as a 👔 Professional, use 🤝 Persuasive tone, Write a 📧 Email for đŸ’ŧ Business Owners.

It should be about a product launch.
Include ROI metrics.
Exclude technical details.

Return as 📄 Plain Text.
""", unsafe_allow_html=True) st.markdown("""
Prompt Structure:
Act as [ROLE], use [TONE] tone, [INSTRUCTION] a [LENGTH] [CONTENT TYPE] for [AUDIENCE].
It should be about [TOPIC].
Include [INCLUSION]. Exclude [EXCLUSION].
Return as [FORMAT].
""", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True)