Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import random
|
| 4 |
import json
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Set page configuration
|
| 7 |
st.set_page_config(page_title="ChatGPT Prompt Generator", page_icon="π§ ", layout="wide")
|
|
@@ -77,6 +79,8 @@ if 'selections' not in st.session_state:
|
|
| 77 |
'content_type': None, 'audience': None, 'format': None,
|
| 78 |
'about': "", 'inclusion': "", 'exclusion': "", 'input_data': ""
|
| 79 |
}
|
|
|
|
|
|
|
| 80 |
|
| 81 |
# Data sets with emoji and names
|
| 82 |
data = {
|
|
@@ -181,6 +185,28 @@ It should be about {sel['about']}."""
|
|
| 181 |
|
| 182 |
return prompt
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
# Header
|
| 185 |
st.markdown("<h2 style='text-align: center; font-size: 1.3rem; margin-bottom: 1rem;'>π§ ChatGPT Prompt Generator</h2>", unsafe_allow_html=True)
|
| 186 |
|
|
@@ -203,7 +229,6 @@ with col1:
|
|
| 203 |
value=st.session_state.selections['about'],
|
| 204 |
placeholder="Enter what the content should be about")
|
| 205 |
|
| 206 |
-
# Use a single-level column for Include/Exclude
|
| 207 |
include_exclude_cols = st.columns(2)
|
| 208 |
with include_exclude_cols[0]:
|
| 209 |
st.session_state.selections['inclusion'] = st.text_input("β
Include",
|
|
@@ -230,10 +255,10 @@ with col2:
|
|
| 230 |
st.write(prompt)
|
| 231 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 232 |
|
| 233 |
-
#
|
| 234 |
-
button_cols = st.columns(
|
| 235 |
with button_cols[0]:
|
| 236 |
-
if st.button("π Copy", type="
|
| 237 |
st.code(prompt, language="")
|
| 238 |
with button_cols[1]:
|
| 239 |
if st.button("π Reset", type="secondary", use_container_width=True):
|
|
@@ -242,15 +267,50 @@ with col2:
|
|
| 242 |
st.session_state.selections[key] = ""
|
| 243 |
else:
|
| 244 |
st.session_state.selections[key] = None
|
|
|
|
| 245 |
st.rerun()
|
| 246 |
with button_cols[2]:
|
| 247 |
if st.button("π² Random", type="secondary", use_container_width=True):
|
| 248 |
for category in ['role', 'tone', 'instruction', 'length', 'content_type', 'audience', 'format']:
|
| 249 |
st.session_state.selections[category] = random.choice(data[category+'s'])
|
| 250 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
st.markdown("<div class='category-header'>π Examples</div>", unsafe_allow_html=True)
|
| 255 |
st.markdown("<div class='dataframe-container'>", unsafe_allow_html=True)
|
| 256 |
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import random
|
| 4 |
import json
|
| 5 |
+
import os
|
| 6 |
+
from datetime import datetime
|
| 7 |
|
| 8 |
# Set page configuration
|
| 9 |
st.set_page_config(page_title="ChatGPT Prompt Generator", page_icon="π§ ", layout="wide")
|
|
|
|
| 79 |
'content_type': None, 'audience': None, 'format': None,
|
| 80 |
'about': "", 'inclusion': "", 'exclusion': "", 'input_data': ""
|
| 81 |
}
|
| 82 |
+
if 'prompt_history' not in st.session_state:
|
| 83 |
+
st.session_state.prompt_history = []
|
| 84 |
|
| 85 |
# Data sets with emoji and names
|
| 86 |
data = {
|
|
|
|
| 185 |
|
| 186 |
return prompt
|
| 187 |
|
| 188 |
+
# Function to save prompt as markdown file
|
| 189 |
+
def save_prompt_as_md(prompt):
|
| 190 |
+
sel = st.session_state.selections
|
| 191 |
+
if not prompt.startswith("Please"):
|
| 192 |
+
# Create an autoname based on components
|
| 193 |
+
components = [
|
| 194 |
+
sel['role']['name'], sel['tone']['name'], sel['instruction']['name'],
|
| 195 |
+
sel['length']['name'], sel['content_type']['name'], sel['audience']['name'],
|
| 196 |
+
sel['format']['name']
|
| 197 |
+
]
|
| 198 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 199 |
+
filename = f"prompt_{'_'.join(comp.lower().replace(' ', '_') for comp in components)}_{timestamp}.md"
|
| 200 |
+
|
| 201 |
+
# Ensure directory exists
|
| 202 |
+
os.makedirs("prompts", exist_ok=True)
|
| 203 |
+
|
| 204 |
+
# Save the file
|
| 205 |
+
with open(os.path.join("prompts", filename), "w") as f:
|
| 206 |
+
f.write(f"```markdown\n{prompt}\n```")
|
| 207 |
+
return filename
|
| 208 |
+
return None
|
| 209 |
+
|
| 210 |
# Header
|
| 211 |
st.markdown("<h2 style='text-align: center; font-size: 1.3rem; margin-bottom: 1rem;'>π§ ChatGPT Prompt Generator</h2>", unsafe_allow_html=True)
|
| 212 |
|
|
|
|
| 229 |
value=st.session_state.selections['about'],
|
| 230 |
placeholder="Enter what the content should be about")
|
| 231 |
|
|
|
|
| 232 |
include_exclude_cols = st.columns(2)
|
| 233 |
with include_exclude_cols[0]:
|
| 234 |
st.session_state.selections['inclusion'] = st.text_input("β
Include",
|
|
|
|
| 255 |
st.write(prompt)
|
| 256 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 257 |
|
| 258 |
+
# Update buttons to include Run
|
| 259 |
+
button_cols = st.columns(4) # Increased to 4 columns to accommodate Run button
|
| 260 |
with button_cols[0]:
|
| 261 |
+
if st.button("π Copy", type="secondary", use_container_width=True):
|
| 262 |
st.code(prompt, language="")
|
| 263 |
with button_cols[1]:
|
| 264 |
if st.button("π Reset", type="secondary", use_container_width=True):
|
|
|
|
| 267 |
st.session_state.selections[key] = ""
|
| 268 |
else:
|
| 269 |
st.session_state.selections[key] = None
|
| 270 |
+
st.session_state.prompt_history = []
|
| 271 |
st.rerun()
|
| 272 |
with button_cols[2]:
|
| 273 |
if st.button("π² Random", type="secondary", use_container_width=True):
|
| 274 |
for category in ['role', 'tone', 'instruction', 'length', 'content_type', 'audience', 'format']:
|
| 275 |
st.session_state.selections[category] = random.choice(data[category+'s'])
|
| 276 |
st.rerun()
|
| 277 |
+
with button_cols[3]:
|
| 278 |
+
if st.button("π Run", type="primary", use_container_width=True):
|
| 279 |
+
if not prompt.startswith("Please"):
|
| 280 |
+
# Display as Markdown code block
|
| 281 |
+
st.code(f"```markdown\n{prompt}\n```", language="markdown")
|
| 282 |
+
|
| 283 |
+
# Save to file
|
| 284 |
+
filename = save_prompt_as_md(prompt)
|
| 285 |
+
if filename:
|
| 286 |
+
st.success(f"Saved as {filename}")
|
| 287 |
+
|
| 288 |
+
# Add to history
|
| 289 |
+
st.session_state.prompt_history.append({
|
| 290 |
+
"prompt": prompt,
|
| 291 |
+
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 292 |
+
"filename": filename
|
| 293 |
+
})
|
| 294 |
+
|
| 295 |
+
# Live updating copy-paste code block
|
| 296 |
+
st.markdown("<div class='category-header'>π Live Prompt Code</div>", unsafe_allow_html=True)
|
| 297 |
+
st.code(f"```markdown\n{prompt}\n```", language="markdown")
|
| 298 |
|
| 299 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 300 |
|
| 301 |
+
# Prompt History
|
| 302 |
+
st.markdown("<div class='category-header'>π Prompt History</div>", unsafe_allow_html=True)
|
| 303 |
+
st.markdown("<div class='dataframe-container'>", unsafe_allow_html=True)
|
| 304 |
+
if st.session_state.prompt_history:
|
| 305 |
+
for i, entry in enumerate(reversed(st.session_state.prompt_history)):
|
| 306 |
+
st.markdown(f"**Prompt {len(st.session_state.prompt_history) - i} ({entry['timestamp']})**")
|
| 307 |
+
st.code(f"```markdown\n{entry['prompt']}\n```", language="markdown")
|
| 308 |
+
st.write(f"Saved as: `{entry['filename']}`")
|
| 309 |
+
else:
|
| 310 |
+
st.write("No prompts generated yet.")
|
| 311 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 312 |
+
|
| 313 |
+
# Examples Section
|
| 314 |
st.markdown("<div class='category-header'>π Examples</div>", unsafe_allow_html=True)
|
| 315 |
st.markdown("<div class='dataframe-container'>", unsafe_allow_html=True)
|
| 316 |
|