Spaces:
Running
Running
File size: 15,404 Bytes
d5fd24d 8bc23f8 d5fd24d 85635d0 d5fd24d 8bc23f8 d5fd24d 85635d0 915e515 6f4a930 85635d0 8bc23f8 d5fd24d 8bc23f8 85635d0 8bc23f8 6f4a930 8bc23f8 d5fd24d 6f4a930 8bc23f8 d5fd24d 8bc23f8 d5fd24d 8bc23f8 d5fd24d 8bc23f8 85635d0 d5fd24d 8bc23f8 85635d0 2960f9a 85635d0 2960f9a 85635d0 2960f9a 85635d0 2960f9a 85635d0 2960f9a 85635d0 2960f9a 85635d0 2960f9a 85635d0 d5fd24d 8bc23f8 85635d0 8bc23f8 85635d0 8bc23f8 85635d0 8bc23f8 85635d0 8bc23f8 85635d0 8bc23f8 d5fd24d 915e515 8bc23f8 d5fd24d 8bc23f8 915e515 8bc23f8 6f4a930 915e515 8bc23f8 85635d0 8bc23f8 6f4a930 8bc23f8 6f4a930 8bc23f8 6f4a930 2960f9a 6f4a930 8bc23f8 6f4a930 2960f9a 8bc23f8 6f4a930 85635d0 d5fd24d 6f4a930 8bc23f8 2960f9a 8bc23f8 6f4a930 8bc23f8 2960f9a 8bc23f8 6f4a930 2960f9a 6f4a930 2960f9a 8bc23f8 6f4a930 8bc23f8 6f4a930 d5fd24d 6f4a930 2960f9a 8bc23f8 d5fd24d 8bc23f8 2960f9a 6f4a930 d5fd24d 2960f9a 8bc23f8 |
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
import streamlit as st
import pandas as pd
import random
import json
# Set page configuration
st.set_page_config(page_title="ChatGPT Prompt Generator", page_icon="๐ง ", layout="wide")
# Custom CSS for styling
st.markdown("""
<style>
.main {background-color: #f8f9fa;}
div[data-testid="stVerticalBlock"] {gap: 0.2rem;}
div[data-testid="stHorizontalBlock"] {gap: 0.3rem;}
.stTextArea textarea, .stTextInput input {
padding: 0.3rem;
font-size: 0.85em;
}
h1, h2, h3 {margin-top: 0; margin-bottom: 0.2rem;}
p, div {margin-bottom: 0.1rem;}
.category-header {
font-weight: bold;
font-size: 1rem;
margin-bottom: 0.2rem;
color: #333;
background-color: #f1f8ff;
padding: 3px 8px;
border-radius: 4px;
}
.prompt-display {
background-color: #ffffff;
border-radius: 4px;
padding: 12px;
border: 1px solid #e9ecef;
min-height: 150px;
white-space: pre-wrap;
}
.st-emotion-cache-1nv1tyf {
font-size: 0.85rem;
}
.dataframe-container {
background-color: white;
border: 1px solid #e6e6e6;
border-radius: 4px;
padding: 8px;
margin-bottom: 8px;
}
.selected-item {
background-color: #007bff !important;
color: white !important;
font-weight: bold;
padding: 2px 6px;
border-radius: 4px;
}
.unselected-item {
background-color: #f8f9fa;
padding: 2px 6px;
border-radius: 4px;
cursor: pointer;
}
.unselected-item:hover {
background-color: #e9ecef;
}
table {
font-size: 0.85rem;
}
.clickable {
cursor: pointer;
}
</style>
""", unsafe_allow_html=True)
# Initialize session state
if 'selections' not in st.session_state:
st.session_state.selections = {
'role': None, 'tone': None, 'instruction': None, 'length': None,
'content_type': None, 'audience': None, 'format': None,
'about': "", 'inclusion': "", 'exclusion': "", 'input_data': ""
}
# Data sets with emoji and names
data = {
'roles': [
{"name": "Professional", "emoji": "๐"}, {"name": "Expert", "emoji": "๐ง "},
{"name": "Friend", "emoji": "๐ค"}, {"name": "Copywriter", "emoji": "โ๏ธ"},
{"name": "Creative Writer", "emoji": "๐๏ธ"}, {"name": "Sales Coach", "emoji": "๐ผ"},
{"name": "Marketing Coach", "emoji": "๐"}, {"name": "Tech Consultant", "emoji": "๐ป"},
{"name": "Life Coach", "emoji": "๐ง"}, {"name": "Data Analyst", "emoji": "๐"},
{"name": "Influencer", "emoji": "๐ฑ"}, {"name": "Language Tutor", "emoji": "๐ฃ๏ธ"},
{"name": "Fitness Trainer", "emoji": "๐ช"}, {"name": "Teacher", "emoji": "๐จโ๐ซ"},
{"name": "Therapist", "emoji": "๐ง"}, {"name": "Detective", "emoji": "๐"}
],
'tones': [
{"name": "Informative", "emoji": "โน๏ธ"}, {"name": "Inspirational", "emoji": "โจ"},
{"name": "Humorous", "emoji": "๐"}, {"name": "Friendly", "emoji": "๐"},
{"name": "Professional", "emoji": "๐"}, {"name": "Casual", "emoji": "๐"},
{"name": "Persuasive", "emoji": "๐ค"}, {"name": "Encouraging", "emoji": "๐"},
{"name": "Empathetic", "emoji": "๐ค"}, {"name": "Serious", "emoji": "๐"},
{"name": "Enthusiastic", "emoji": "๐คฉ"}, {"name": "Thoughtful", "emoji": "๐ญ"}
],
'instructions': [
{"name": "Create", "emoji": "๐จ"}, {"name": "Suggest", "emoji": "๐ก"},
{"name": "Write", "emoji": "โ๏ธ"}, {"name": "Compose", "emoji": "๐"},
{"name": "Analyze", "emoji": "๐"}, {"name": "Explain", "emoji": "๐"},
{"name": "Describe", "emoji": "๐"}, {"name": "Summarize", "emoji": "๐"},
{"name": "Compare", "emoji": "โ๏ธ"}, {"name": "Outline", "emoji": "๐"},
{"name": "Evaluate", "emoji": "โญ"}, {"name": "List", "emoji": "๐"}
],
'lengths': [
{"name": "300 Words", "emoji": "๐"}, {"name": "500 Words", "emoji": "๐"},
{"name": "Short", "emoji": "๐ฉณ"}, {"name": "Medium", "emoji": "๐"},
{"name": "Long", "emoji": "๐"}, {"name": "Brief", "emoji": "๐จ"},
{"name": "Detailed", "emoji": "๐"}, {"name": "Comprehensive", "emoji": "๐"}
],
'content_types': [
{"name": "Article", "emoji": "๐ฐ"}, {"name": "Blog post", "emoji": "๐"},
{"name": "Guide", "emoji": "๐"}, {"name": "Email", "emoji": "๐ง"},
{"name": "Summary", "emoji": "๐"}, {"name": "Story", "emoji": "๐"},
{"name": "Essay", "emoji": "๐"}, {"name": "Review", "emoji": "โญ"},
{"name": "Tutorial", "emoji": "๐จโ๐ซ"}, {"name": "Report", "emoji": "๐"},
{"name": "Plan", "emoji": "๐"}, {"name": "Script", "emoji": "๐ฌ"}
],
'audiences': [
{"name": "Beginners", "emoji": "๐ฑ"}, {"name": "Experts", "emoji": "๐ง "},
{"name": "Students", "emoji": "๐"}, {"name": "Professionals", "emoji": "๐"},
{"name": "Business Owners", "emoji": "๐ผ"}, {"name": "General Public", "emoji": "๐ฅ"},
{"name": "Developers", "emoji": "๐ป"}, {"name": "Children", "emoji": "๐ถ"}
],
'formats': [
{"name": "Markdown", "emoji": "๐"}, {"name": "HTML", "emoji": "๐"},
{"name": "Plain Text", "emoji": "๐"}, {"name": "JSON", "emoji": "๐"},
{"name": "PDF", "emoji": "๐"}, {"name": "Python Code", "emoji": "๐"},
{"name": "JavaScript", "emoji": "๐"}, {"name": "SQL Query", "emoji": "๐พ"}
]
}
# Function to convert data to dataframe rows
def create_dataframe_rows(items, cols=4):
# Calculate how many rows we need based on items and columns
num_rows = (len(items) + cols - 1) // cols
# Create empty rows
rows = [["" for _ in range(cols)] for _ in range(num_rows)]
# Fill in the values
for i, item in enumerate(items):
row_idx = i // cols
col_idx = i % cols
rows[row_idx][col_idx] = f"{item['emoji']} {item['name']}"
return rows
# Function to handle cell click events
def handle_selection(category, value):
# Extract the name without emoji
parts = value.split(' ', 1)
if len(parts) < 2:
return
emoji = parts[0]
name = parts[1]
# Find the item in the data
for item in data[f"{category}s"]:
if item['name'] == name:
st.session_state.selections[category] = item
return
# If not found (shouldn't happen)
st.session_state.selections[category] = {"name": name, "emoji": emoji}
# Function to create dataframe with click handler
def create_dataframe_category(category, title, emoji_prefix):
# Create the dataframe content
df_rows = create_dataframe_rows(data[f"{category}s"], cols=4)
df = pd.DataFrame(df_rows)
# Display the category header
st.markdown(f"<div class='category-header'>{emoji_prefix} {title}</div>", unsafe_allow_html=True)
# Display in a container
st.markdown(f"<div class='dataframe-container'>", unsafe_allow_html=True)
# Use an edited dataframe
edited_df = st.data_editor(
df,
key=f"df_{category}",
hide_index=True,
column_config={
i: st.column_config.Column(
label=f"Option {i+1}",
width="small",
) for i in range(df.shape[1])
},
disabled=True,
use_container_width=True,
on_click=lambda e: handle_selection(category, e.current)
)
# Check if there's a selected value to highlight
if st.session_state.selections[category]:
selected_value = f"{st.session_state.selections[category]['emoji']} {st.session_state.selections[category]['name']}"
# Since we can't style specific cells in the dataframe editor, we can indicate the selection another way
selected_index = None
for i, row in df.iterrows():
for j, cell in enumerate(row):
if cell == selected_value:
selected_index = (i, j)
break
if selected_index:
break
if selected_index:
st.markdown(f"Selected: **{selected_value}**", unsafe_allow_html=True)
st.markdown("</div>", unsafe_allow_html=True)
# Function to generate the final prompt
def generate_prompt():
sel = st.session_state.selections
# Check if all required fields are selected
if not all([sel['role'], sel['tone'], sel['instruction'], sel['length'],
sel['content_type'], sel['audience'], sel['format'], sel['about']]):
return "Please select all required components and provide a topic."
# Generate the prompt
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']}.
It should be about {sel['about']}."""
if sel['inclusion']:
prompt += f"\nInclude {sel['inclusion']}."
if sel['exclusion']:
prompt += f"\nExclude {sel['exclusion']}."
prompt += f"\n\nReturn the output as {sel['format']['emoji']} {sel['format']['name']}."
if sel['input_data']:
prompt += f"\nUse the following information: {sel['input_data']}"
return prompt
# Header
st.markdown("<h2 style='text-align: center; font-size: 1.3rem; margin-bottom: 1rem;'>๐ง ChatGPT Prompt Generator</h2>", unsafe_allow_html=True)
# Main layout with two columns
col1, col2 = st.columns([3, 1])
with col1:
# Create dataframes for each category
create_dataframe_category("role", "Choose a Role", "๐ค")
create_dataframe_category("tone", "Select a Tone", "๐ญ")
create_dataframe_category("instruction", "Select an Instruction", "๐")
create_dataframe_category("length", "Select Length", "๐")
create_dataframe_category("content_type", "Select Content Type", "๐")
create_dataframe_category("audience", "Select Target Audience", "๐ฅ")
create_dataframe_category("format", "Select Format", "๐")
# Text input fields
st.markdown("<div class='category-header'>๐ Additional Details</div>", unsafe_allow_html=True)
st.markdown("<div class='dataframe-container'>", unsafe_allow_html=True)
st.session_state.selections['about'] = st.text_input("๐ฌ Topic",
value=st.session_state.selections['about'],
placeholder="Enter what the content should be about")
col1, col2 = st.columns(2)
with col1:
st.session_state.selections['inclusion'] = st.text_input("โ
Include",
value=st.session_state.selections['inclusion'],
placeholder="What to include in the content")
with col2:
st.session_state.selections['exclusion'] = st.text_input("โ Exclude",
value=st.session_state.selections['exclusion'],
placeholder="What to exclude from the content")
st.session_state.selections['input_data'] = st.text_area("๐ Input Data",
value=st.session_state.selections['input_data'],
placeholder="Enter any specific information to use",
height=100)
st.markdown("</div>", unsafe_allow_html=True)
with col2:
# Generate the prompt
prompt = generate_prompt()
# Display the prompt
st.markdown("<div class='category-header'>๐ฎ Generated Prompt</div>", unsafe_allow_html=True)
st.markdown("<div class='dataframe-container'>", unsafe_allow_html=True)
st.markdown("<div class='prompt-display'>", unsafe_allow_html=True)
st.write(prompt)
st.markdown("</div>", unsafe_allow_html=True)
# Action buttons
btn1, btn2, btn3 = st.columns(3)
with btn1:
if st.button("๐ Copy", type="primary", use_container_width=True):
st.code(prompt, language="")
with btn2:
if st.button("๐ Reset", type="secondary", use_container_width=True):
for key in st.session_state.selections:
if key in ['about', 'inclusion', 'exclusion', 'input_data']:
st.session_state.selections[key] = ""
else:
st.session_state.selections[key] = None
st.experimental_rerun()
with btn3:
if st.button("๐ฒ Random", type="secondary", use_container_width=True):
for category in ['role', 'tone', 'instruction', 'length', 'content_type', 'audience', 'format']:
st.session_state.selections[category] = random.choice(data[category+'s'])
st.experimental_rerun()
st.markdown("</div>", unsafe_allow_html=True)
# Sample prompts section
st.markdown("<div class='category-header'>๐ Examples</div>", unsafe_allow_html=True)
st.markdown("<div class='dataframe-container'>", unsafe_allow_html=True)
# Example 1
st.markdown("""
<div style="background-color: #e6f3ff; border: 1px solid #b8daff; border-radius: 4px; padding: 6px; margin-bottom: 6px; font-size: 0.8em;">
<b>๐จโ๐ซ Teaching</b><pre style="white-space: pre-wrap; font-size: 0.8em; margin: 3px 0px;">Act as a ๐จโ๐ซ Teacher, use ๐ Informative tone, Create a ๐ Guide for ๐ฑ Beginners.
It should be about Git.
Include practical examples.
Exclude advanced techniques.
Return as ๐ Markdown.</pre>
</div>
""", unsafe_allow_html=True)
# Example 2
st.markdown("""
<div style="background-color: #e6ffed; border: 1px solid #b8e6cc; border-radius: 4px; padding: 6px; margin-bottom: 6px; font-size: 0.8em;">
<b>๐ผ Business</b><pre style="white-space: pre-wrap; font-size: 0.8em; margin: 3px 0px;">Act as a ๐ Professional, use ๐ค Persuasive tone, Write a ๐ง Email for ๐ฉโ๐ผ Executives.
It should be about a product launch.
Include ROI metrics.
Exclude technical details.
Return as ๐ Plain Text.</pre>
</div>
""", unsafe_allow_html=True)
# Prompt structure guide
st.markdown("""
<div style="background-color: #f1f8ff; border-radius: 4px; padding: 6px; margin-top: 6px; font-size: 0.8em;">
<b>Prompt Structure:</b><br>
Act as [<span style="color:blue">ROLE</span>], use [<span style="color:green">TONE</span>] tone, [<span style="color:red">INSTRUCTION</span>] a [<span style="color:purple">LENGTH</span>] [<span style="color:orange">CONTENT TYPE</span>] for [<span style="color:pink">AUDIENCE</span>].<br>
It should be about [TOPIC].<br>
Include [INCLUSION]. Exclude [EXCLUSION].<br>
Return as [FORMAT].
</div>
""", unsafe_allow_html=True)
st.markdown("</div>", unsafe_allow_html=True) |