Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Configure the page settings
|
| 4 |
+
def configure_page():
|
| 5 |
+
st.set_page_config(
|
| 6 |
+
page_title="AI Instruction Processor",
|
| 7 |
+
page_icon="🤖",
|
| 8 |
+
layout="wide"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Apply custom styling
|
| 12 |
+
st.markdown("""
|
| 13 |
+
<style>
|
| 14 |
+
.reportview-container {
|
| 15 |
+
background: #0e1117;
|
| 16 |
+
color: #ffffff;
|
| 17 |
+
}
|
| 18 |
+
.stTextInput > div > div > input {
|
| 19 |
+
background-color: #2b303b;
|
| 20 |
+
color: #ffffff;
|
| 21 |
+
}
|
| 22 |
+
.stTextArea > div > div > textarea {
|
| 23 |
+
background-color: #2b303b;
|
| 24 |
+
color: #ffffff;
|
| 25 |
+
}
|
| 26 |
+
</style>
|
| 27 |
+
""", unsafe_allow_html=True)
|
| 28 |
+
|
| 29 |
+
# Define the instruction template with placeholder
|
| 30 |
+
INSTRUCTION_TEMPLATE = """
|
| 31 |
+
Improve the following text according to these guidelines:
|
| 32 |
+
- Make the language more professional and concise
|
| 33 |
+
- Fix any grammar or spelling errors
|
| 34 |
+
- Enhance clarity and readability
|
| 35 |
+
- Maintain the original meaning
|
| 36 |
+
|
| 37 |
+
[INPUT_PLACEHOLDER]
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
def process_input(user_input):
|
| 41 |
+
"""Process the user input with the instruction template."""
|
| 42 |
+
return INSTRUCTION_TEMPLATE.replace("[INPUT_PLACEHOLDER]", user_input)
|
| 43 |
+
|
| 44 |
+
def display_history():
|
| 45 |
+
"""Display the conversation history."""
|
| 46 |
+
st.markdown("### Previous Prompts")
|
| 47 |
+
if 'conversation_history' in st.session_state:
|
| 48 |
+
for idx, item in enumerate(reversed(st.session_state.conversation_history)):
|
| 49 |
+
with st.expander(f"Prompt {len(st.session_state.conversation_history) - idx}", expanded=True):
|
| 50 |
+
st.markdown("**Input Text:**")
|
| 51 |
+
st.markdown(f"```\n{item['input']}\n```")
|
| 52 |
+
st.markdown("**Generated Prompt:**")
|
| 53 |
+
st.markdown(f"```\n{item['output']}\n```")
|
| 54 |
+
|
| 55 |
+
def main():
|
| 56 |
+
# Configure the page
|
| 57 |
+
configure_page()
|
| 58 |
+
|
| 59 |
+
# Initialize session state for conversation history
|
| 60 |
+
if 'conversation_history' not in st.session_state:
|
| 61 |
+
st.session_state.conversation_history = []
|
| 62 |
+
|
| 63 |
+
# Main title and description
|
| 64 |
+
st.title("🤖 AI Instruction Processor")
|
| 65 |
+
st.markdown("Transform your input text using our predefined instruction set.")
|
| 66 |
+
|
| 67 |
+
# Create two-column layout
|
| 68 |
+
left_col, right_col = st.columns([2, 1])
|
| 69 |
+
|
| 70 |
+
with left_col:
|
| 71 |
+
# Input area
|
| 72 |
+
user_input = st.text_area(
|
| 73 |
+
"Enter your text:",
|
| 74 |
+
height=200,
|
| 75 |
+
placeholder="Paste your text here...",
|
| 76 |
+
key="input_area"
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# Process button
|
| 80 |
+
if st.button("Generate Prompt", type="primary"):
|
| 81 |
+
if user_input:
|
| 82 |
+
# Generate the prompt
|
| 83 |
+
result = process_input(user_input)
|
| 84 |
+
|
| 85 |
+
# Save to conversation history
|
| 86 |
+
st.session_state.conversation_history.append({
|
| 87 |
+
'input': user_input,
|
| 88 |
+
'output': result
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
# Display the result
|
| 92 |
+
st.markdown("### Generated Prompt:")
|
| 93 |
+
st.markdown(f"```\n{result}\n```")
|
| 94 |
+
|
| 95 |
+
# Display history in right column
|
| 96 |
+
with right_col:
|
| 97 |
+
display_history()
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
main()
|