Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from datetime import datetime
|
|
| 7 |
import base64
|
| 8 |
|
| 9 |
# Set page configuration
|
| 10 |
-
st.set_page_config(page_title="
|
| 11 |
|
| 12 |
# Custom CSS for styling
|
| 13 |
st.markdown("""
|
|
@@ -37,6 +37,7 @@ st.markdown("""
|
|
| 37 |
border: 1px solid #e9ecef;
|
| 38 |
min-height: 150px;
|
| 39 |
white-space: pre-wrap;
|
|
|
|
| 40 |
}
|
| 41 |
.st-emotion-cache-1nv1tyf {
|
| 42 |
font-size: 0.85rem;
|
|
@@ -73,12 +74,13 @@ st.markdown("""
|
|
| 73 |
</style>
|
| 74 |
""", unsafe_allow_html=True)
|
| 75 |
|
| 76 |
-
# Initialize session state
|
| 77 |
if 'selections' not in st.session_state:
|
| 78 |
st.session_state.selections = {
|
| 79 |
'role': None, 'tone': None, 'instruction': None, 'length': None,
|
| 80 |
'content_type': None, 'audience': None, 'format': None,
|
| 81 |
-
'about': "
|
|
|
|
| 82 |
}
|
| 83 |
if 'prompt_history' not in st.session_state:
|
| 84 |
st.session_state.prompt_history = []
|
|
@@ -135,7 +137,9 @@ data = {
|
|
| 135 |
{"name": "Markdown", "emoji": "๐"}, {"name": "HTML", "emoji": "๐"},
|
| 136 |
{"name": "Plain Text", "emoji": "๐"}, {"name": "JSON", "emoji": "๐"},
|
| 137 |
{"name": "PDF", "emoji": "๐"}, {"name": "Python Code", "emoji": "๐"},
|
| 138 |
-
{"name": "JavaScript", "emoji": "๐"}, {"name": "SQL Query", "emoji": "๐พ"}
|
|
|
|
|
|
|
| 139 |
]
|
| 140 |
}
|
| 141 |
|
|
@@ -166,8 +170,8 @@ def generate_prompt():
|
|
| 166 |
sel = st.session_state.selections
|
| 167 |
|
| 168 |
if not all([sel['role'], sel['tone'], sel['instruction'], sel['length'],
|
| 169 |
-
sel['content_type'], sel['audience'], sel['format']
|
| 170 |
-
return "Please select all required components
|
| 171 |
|
| 172 |
prompt = f"""Act as a {sel['role']['emoji']} {sel['role']['name']}, use {sel['tone']['emoji']} {sel['tone']['name']} tone, {sel['instruction']['emoji']} {sel['instruction']['name']} a {sel['length']['emoji']} {sel['length']['name']} {sel['content_type']['emoji']} {sel['content_type']['name']} for {sel['audience']['emoji']} {sel['audience']['name']}.
|
| 173 |
|
|
@@ -218,19 +222,28 @@ def get_base64_download_link(filepath):
|
|
| 218 |
filename = os.path.basename(filepath)
|
| 219 |
return f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">Download {filename}</a>'
|
| 220 |
|
| 221 |
-
# Sidebar
|
| 222 |
with st.sidebar:
|
| 223 |
st.markdown("### ๐ Saved Prompts")
|
| 224 |
md_files = get_saved_md_files()
|
| 225 |
if md_files:
|
| 226 |
-
for md_file in sorted(md_files, reverse=True):
|
| 227 |
filepath = os.path.join("prompts", md_file)
|
| 228 |
st.markdown(f"- {get_base64_download_link(filepath)}", unsafe_allow_html=True)
|
| 229 |
else:
|
| 230 |
st.write("No saved prompts yet.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
# Header
|
| 233 |
-
st.markdown("<h2 style='text-align: center; font-size: 1.3rem; margin-bottom: 1rem;'
|
| 234 |
|
| 235 |
# Main layout with two columns
|
| 236 |
col1, col2 = st.columns([3, 1])
|
|
@@ -273,8 +286,8 @@ with col2:
|
|
| 273 |
|
| 274 |
st.markdown("<div class='category-header'>๐ฎ Generated Prompt</div>", unsafe_allow_html=True)
|
| 275 |
st.markdown("<div class='dataframe-container'>", unsafe_allow_html=True)
|
| 276 |
-
st.
|
| 277 |
-
|
| 278 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 279 |
|
| 280 |
button_cols = st.columns(4)
|
|
@@ -285,7 +298,7 @@ with col2:
|
|
| 285 |
if st.button("๐ Reset", type="secondary", use_container_width=True):
|
| 286 |
for key in st.session_state.selections:
|
| 287 |
if key in ['about', 'inclusion', 'exclusion', 'input_data']:
|
| 288 |
-
st.session_state.selections[key] = ""
|
| 289 |
else:
|
| 290 |
st.session_state.selections[key] = None
|
| 291 |
st.session_state.prompt_history = []
|
|
|
|
| 7 |
import base64
|
| 8 |
|
| 9 |
# Set page configuration
|
| 10 |
+
st.set_page_config(page_title="PromptWizardry", page_icon="๐ง ", layout="wide")
|
| 11 |
|
| 12 |
# Custom CSS for styling
|
| 13 |
st.markdown("""
|
|
|
|
| 37 |
border: 1px solid #e9ecef;
|
| 38 |
min-height: 150px;
|
| 39 |
white-space: pre-wrap;
|
| 40 |
+
font-size: 0.85em;
|
| 41 |
}
|
| 42 |
.st-emotion-cache-1nv1tyf {
|
| 43 |
font-size: 0.85rem;
|
|
|
|
| 74 |
</style>
|
| 75 |
""", unsafe_allow_html=True)
|
| 76 |
|
| 77 |
+
# Initialize session state with default topic
|
| 78 |
if 'selections' not in st.session_state:
|
| 79 |
st.session_state.selections = {
|
| 80 |
'role': None, 'tone': None, 'instruction': None, 'length': None,
|
| 81 |
'content_type': None, 'audience': None, 'format': None,
|
| 82 |
+
'about': "DistillKit, MergeKit, Spectrum for ML Model Building from input Spreadsheets using torch, transformers and Streamlit",
|
| 83 |
+
'inclusion': "", 'exclusion': "", 'input_data': ""
|
| 84 |
}
|
| 85 |
if 'prompt_history' not in st.session_state:
|
| 86 |
st.session_state.prompt_history = []
|
|
|
|
| 137 |
{"name": "Markdown", "emoji": "๐"}, {"name": "HTML", "emoji": "๐"},
|
| 138 |
{"name": "Plain Text", "emoji": "๐"}, {"name": "JSON", "emoji": "๐"},
|
| 139 |
{"name": "PDF", "emoji": "๐"}, {"name": "Python Code", "emoji": "๐"},
|
| 140 |
+
{"name": "JavaScript", "emoji": "๐"}, {"name": "SQL Query", "emoji": "๐พ"},
|
| 141 |
+
{"name": "Image Gen Prompt", "emoji": "๐ผ๏ธ"}, {"name": "Video Gen Prompt", "emoji": "๐ฅ"},
|
| 142 |
+
{"name": "Song Gen Prompt", "emoji": "๐ต"}, {"name": "Story Gen Prompt", "emoji": "๐"}
|
| 143 |
]
|
| 144 |
}
|
| 145 |
|
|
|
|
| 170 |
sel = st.session_state.selections
|
| 171 |
|
| 172 |
if not all([sel['role'], sel['tone'], sel['instruction'], sel['length'],
|
| 173 |
+
sel['content_type'], sel['audience'], sel['format']]):
|
| 174 |
+
return "Please select all required components."
|
| 175 |
|
| 176 |
prompt = f"""Act as a {sel['role']['emoji']} {sel['role']['name']}, use {sel['tone']['emoji']} {sel['tone']['name']} tone, {sel['instruction']['emoji']} {sel['instruction']['name']} a {sel['length']['emoji']} {sel['length']['name']} {sel['content_type']['emoji']} {sel['content_type']['name']} for {sel['audience']['emoji']} {sel['audience']['name']}.
|
| 177 |
|
|
|
|
| 222 |
filename = os.path.basename(filepath)
|
| 223 |
return f'<a href="data:application/octet-stream;base64,{b64}" download="{filename}">Download {filename}</a>'
|
| 224 |
|
| 225 |
+
# Sidebar with Saved Prompts and Feature Outline
|
| 226 |
with st.sidebar:
|
| 227 |
st.markdown("### ๐ Saved Prompts")
|
| 228 |
md_files = get_saved_md_files()
|
| 229 |
if md_files:
|
| 230 |
+
for md_file in sorted(md_files, reverse=True):
|
| 231 |
filepath = os.path.join("prompts", md_file)
|
| 232 |
st.markdown(f"- {get_base64_download_link(filepath)}", unsafe_allow_html=True)
|
| 233 |
else:
|
| 234 |
st.write("No saved prompts yet.")
|
| 235 |
+
|
| 236 |
+
st.markdown("### ๐ PromptWizardry Magic")
|
| 237 |
+
st.markdown("""
|
| 238 |
+
- ๐ **Prompt Alchemy**: Craft with roles, tones, & more!
|
| 239 |
+
- ๐ช **Actions**: Copy, Reset, Random, Run!
|
| 240 |
+
- ๐พ **Scroll Vault**: Save & download `.md` spells!
|
| 241 |
+
- โณ **Chronicles**: Relive your magic history!
|
| 242 |
+
- ๐ **Extras**: Sample spells & dazzling UI!
|
| 243 |
+
""")
|
| 244 |
|
| 245 |
# Header
|
| 246 |
+
st.markdown("<h2 style='text-align: center; font-size: 1.3rem; margin-bottom: 1rem;'>โจ PromptWizardry</h2>", unsafe_allow_html=True)
|
| 247 |
|
| 248 |
# Main layout with two columns
|
| 249 |
col1, col2 = st.columns([3, 1])
|
|
|
|
| 286 |
|
| 287 |
st.markdown("<div class='category-header'>๐ฎ Generated Prompt</div>", unsafe_allow_html=True)
|
| 288 |
st.markdown("<div class='dataframe-container'>", unsafe_allow_html=True)
|
| 289 |
+
st.text_area("", value=prompt, height=150, key="generated_prompt", disabled=True,
|
| 290 |
+
help="Your magical prompt appears here!")
|
| 291 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 292 |
|
| 293 |
button_cols = st.columns(4)
|
|
|
|
| 298 |
if st.button("๐ Reset", type="secondary", use_container_width=True):
|
| 299 |
for key in st.session_state.selections:
|
| 300 |
if key in ['about', 'inclusion', 'exclusion', 'input_data']:
|
| 301 |
+
st.session_state.selections[key] = "" if key != 'about' else "DistillKit, MergeKit, Spectrum for ML Model Building from input Spreadsheets using torch, transformers and Streamlit"
|
| 302 |
else:
|
| 303 |
st.session_state.selections[key] = None
|
| 304 |
st.session_state.prompt_history = []
|