|
import streamlit as st |
|
|
|
|
|
def configure_page(): |
|
st.set_page_config( |
|
page_title="AI Instruction Processor", |
|
page_icon="π€", |
|
layout="wide" |
|
) |
|
|
|
|
|
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) |
|
|
|
|
|
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_page() |
|
|
|
|
|
if 'conversation_history' not in st.session_state: |
|
st.session_state.conversation_history = [] |
|
|
|
|
|
st.title("π€ AI Instruction Processor") |
|
st.markdown("Transform your input text using our predefined instruction set.") |
|
|
|
|
|
left_col, right_col = st.columns([2, 1]) |
|
|
|
with left_col: |
|
|
|
user_input = st.text_area( |
|
"Enter your text:", |
|
height=200, |
|
placeholder="Paste your text here...", |
|
key="input_area" |
|
) |
|
|
|
|
|
if st.button("Generate Prompt", type="primary"): |
|
if user_input: |
|
|
|
result = process_input(user_input) |
|
|
|
|
|
st.session_state.conversation_history.append({ |
|
'input': user_input, |
|
'output': result |
|
}) |
|
|
|
|
|
st.markdown("### Generated Prompt:") |
|
st.markdown(f"```\n{result}\n```") |
|
|
|
|
|
with right_col: |
|
display_history() |
|
|
|
if __name__ == "__main__": |
|
main() |