import streamlit as st # Configure the page settings def configure_page(): st.set_page_config( page_title="AI Instruction Processor", page_icon="🤖", layout="wide" ) # Apply custom styling st.markdown(""" """, unsafe_allow_html=True) # Define the instruction template with placeholder INSTRUCTION_TEMPLATE = """ Improve the following text according to these guidelines: - Make the language more professional and concise - Fix any grammar or spelling errors - Enhance clarity and readability - Maintain the original meaning [INPUT_PLACEHOLDER] """ def process_input(user_input): """Process the user input with the instruction template.""" return INSTRUCTION_TEMPLATE.replace("[INPUT_PLACEHOLDER]", user_input) def display_history(): """Display the conversation history.""" st.markdown("### Previous Prompts") if 'conversation_history' in st.session_state: for idx, item in enumerate(reversed(st.session_state.conversation_history)): with st.expander(f"Prompt {len(st.session_state.conversation_history) - idx}", expanded=True): st.markdown("**Input Text:**") st.markdown(f"```\n{item['input']}\n```") st.markdown("**Generated Prompt:**") st.markdown(f"```\n{item['output']}\n```") def main(): # Configure the page configure_page() # Initialize session state for conversation history if 'conversation_history' not in st.session_state: st.session_state.conversation_history = [] # Main title and description st.title("🤖 AI Instruction Processor") st.markdown("Transform your input text using our predefined instruction set.") # Create two-column layout left_col, right_col = st.columns([2, 1]) with left_col: # Input area user_input = st.text_area( "Enter your text:", height=200, placeholder="Paste your text here...", key="input_area" ) # Process button if st.button("Generate Prompt", type="primary"): if user_input: # Generate the prompt result = process_input(user_input) # Save to conversation history st.session_state.conversation_history.append({ 'input': user_input, 'output': result }) # Display the result st.markdown("### Generated Prompt:") st.markdown(f"```\n{result}\n```") # Display history in right column with right_col: display_history() if __name__ == "__main__": main()