File size: 3,119 Bytes
3098523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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("""
        <style>
        .reportview-container { 
            background: #0e1117; 
            color: #ffffff; 
        }
        .stTextInput > div > div > input { 
            background-color: #2b303b; 
            color: #ffffff; 
        }
        .stTextArea > div > div > textarea { 
            background-color: #2b303b; 
            color: #ffffff; 
        }
        </style>
    """, 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()