Spaces:
Running
Running
import streamlit as st | |
import pandas as pd | |
import random | |
# Set page configuration | |
st.set_page_config(page_title="ChatGPT Prompt Generator", page_icon="π§ ", layout="wide") | |
# Custom CSS for ultra-compact layout with wide columns | |
st.markdown(""" | |
<style> | |
.main {background-color: #f8f9fa;} | |
.stButton button { | |
border-radius: 4px; | |
padding: 1px 3px; | |
font-size: 0.7em; | |
display: inline-flex; | |
align-items: center; | |
margin: 1px; | |
min-height: 0px; | |
white-space: nowrap; | |
} | |
.stButton button:hover {background-color: #e9ecef;} | |
div[data-testid="stVerticalBlock"] {gap: 0.3rem;} | |
div[data-testid="stHorizontalBlock"] {gap: 0.3rem;} | |
.stTextArea textarea, .stTextInput input { | |
padding: 0.2rem; | |
font-size: 0.7em; | |
min-height: 0px; | |
} | |
div[data-testid="stForm"] {border-width: 0px; padding: 0rem 0rem;} | |
.row-widget.stRadio > div {flex-direction: row;} | |
.row-widget.stRadio > div > label {margin: 0px 0.1rem; padding: 0.1rem 0.3rem; font-size: 0.7em;} | |
h1, h2, h3 {margin-top: 0; margin-bottom: 0.1rem; font-size: 0.9rem;} | |
p, div {margin-bottom: 0.1rem; font-size: 0.8rem;} | |
.wide-grid-container { | |
display: grid; | |
grid-template-columns: repeat(10, 1fr); | |
gap: 2px; | |
} | |
.section-header { | |
font-weight: bold; | |
font-size: 0.9rem; | |
margin-bottom: 0.1rem; | |
margin-top: 0.2rem; | |
color: #333; | |
} | |
.prompt-display { | |
background-color: #ffffff; | |
border-radius: 4px; | |
padding: 8px; | |
border: 1px solid #e9ecef; | |
min-height: 100px; | |
font-size: 0.8em; | |
white-space: pre-wrap; | |
} | |
.sample-prompt { | |
font-size: 0.7em; | |
padding: 3px; | |
border-radius: 4px; | |
margin-bottom: 3px; | |
} | |
.emoji {font-size: 0.9em;} | |
</style> | |
""", unsafe_allow_html=True) | |
# Initialize session state for selections | |
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 | |
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": "π"}, | |
{"name": "Journalist", "emoji": "π°"}, {"name": "Scientist", "emoji": "π¬"}, | |
{"name": "Chef", "emoji": "π¨βπ³"}, {"name": "Artist", "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": "π"}, | |
{"name": "Sarcastic", "emoji": "π"}, {"name": "Motivated", "emoji": "πͺ"}, | |
{"name": "Critical", "emoji": "π§"}, {"name": "Optimistic", "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": "π"}, | |
{"name": "Draft", "emoji": "π"}, {"name": "Review", "emoji": "ποΈ"}, | |
{"name": "Generate", "emoji": "βοΈ"}, {"name": "Plan", "emoji": "ποΈ"} | |
], | |
'lengths': [ | |
{"name": "100 Words", "emoji": "π"}, {"name": "300 Words", "emoji": "π"}, | |
{"name": "500 Words", "emoji": "π"}, {"name": "1000 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": "π¬"}, | |
{"name": "Outline", "emoji": "π"}, {"name": "Letter", "emoji": "βοΈ"}, | |
{"name": "Presentation", "emoji": "π―"}, {"name": "Analysis", "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": "πΆ"}, | |
{"name": "Executives", "emoji": "π©βπΌ"}, {"name": "Seniors", "emoji": "π΅"}, | |
{"name": "Teachers", "emoji": "π©βπ«"}, {"name": "Parents", "emoji": "πͺ"} | |
], | |
'formats': [ | |
{"name": "Markdown", "emoji": "π"}, {"name": "HTML", "emoji": "π"}, | |
{"name": "Plain Text", "emoji": "π"}, {"name": "JSON", "emoji": "π"}, | |
{"name": "PDF", "emoji": "π"}, {"name": "Python", "emoji": "π"}, | |
{"name": "JavaScript", "emoji": "π"}, {"name": "SQL", "emoji": "πΎ"}, | |
{"name": "CSV", "emoji": "π"}, {"name": "XML", "emoji": "π"} | |
] | |
} | |
# Function to create buttons for a category in a wide grid | |
def create_wide_grid_buttons(category_name, items): | |
st.markdown(f"<div class='section-header'>{category_name}</div>", unsafe_allow_html=True) | |
st.markdown("<div class='wide-grid-container'>", unsafe_allow_html=True) | |
for i, item in enumerate(items): | |
key = f"{category_name.lower().replace(' ', '_')}_{i}" | |
is_selected = st.session_state.selections.get(category_name.lower().replace(' ', '_')) == item | |
button_type = "primary" if is_selected else "secondary" | |
if st.button(f"{item['emoji']} {item['name']}", key=key, help=f"Select {item['name']}", | |
type=button_type, use_container_width=True): | |
st.session_state.selections[category_name.lower().replace(' ', '_')] = item | |
st.experimental_rerun() | |
st.markdown("</div>", unsafe_allow_html=True) | |
# Minimal header | |
st.markdown("<h2 style='text-align: center; font-size: 1.2rem;'><span class='emoji'>π§ </span> ChatGPT Prompt Generator</h2>", unsafe_allow_html=True) | |
# Main layout - Two rows with many columns | |
row1, row2 = st.columns([7, 3]) | |
with row1: | |
# First set of categories | |
col1, col2 = st.columns(2) | |
with col1: | |
create_wide_grid_buttons("Role", data['roles']) | |
create_wide_grid_buttons("Tone", data['tones']) | |
create_wide_grid_buttons("Instruction", data['instructions']) | |
with col2: | |
create_wide_grid_buttons("Length", data['lengths']) | |
create_wide_grid_buttons("Content Type", data['content_types']) | |
create_wide_grid_buttons("Audience", data['audiences']) | |
# Format and text fields in a more compact layout | |
format_col, inputs_col = st.columns([2, 8]) | |
with format_col: | |
create_wide_grid_buttons("Format", data['formats']) | |
with inputs_col: | |
text_col1, text_col2, text_col3, text_col4 = st.columns(4) | |
with text_col1: | |
st.session_state.selections['about'] = st.text_input("π¬ Topic", | |
value=st.session_state.selections['about'], | |
placeholder="Enter topic", | |
label_visibility="collapsed") | |
with text_col2: | |
st.session_state.selections['inclusion'] = st.text_input("β Include", | |
value=st.session_state.selections['inclusion'], | |
placeholder="What to include", | |
label_visibility="collapsed") | |
with text_col3: | |
st.session_state.selections['exclusion'] = st.text_input("β Exclude", | |
value=st.session_state.selections['exclusion'], | |
placeholder="What to exclude", | |
label_visibility="collapsed") | |
with text_col4: | |
st.session_state.selections['input_data'] = st.text_input("π Data", | |
value=st.session_state.selections['input_data'], | |
placeholder="Input data", | |
label_visibility="collapsed") | |
with row2: | |
# Generate prompt based on selections | |
is_complete = all([ | |
st.session_state.selections['role'], st.session_state.selections['tone'], | |
st.session_state.selections['instruction'], st.session_state.selections['length'], | |
st.session_state.selections['content_type'], st.session_state.selections['audience'], | |
st.session_state.selections['format'], st.session_state.selections['about'] | |
]) | |
prompt = "" | |
if is_complete: | |
sel = st.session_state.selections | |
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']}" | |
else: | |
prompt = "Select all required components and provide a topic." | |
st.markdown("<div class='prompt-display'>", unsafe_allow_html=True) | |
st.write(prompt) | |
st.markdown("</div>", unsafe_allow_html=True) | |
# Action buttons in a row | |
button_col1, button_col2, button_col3 = st.columns(3) | |
with button_col1: | |
if st.button("π Copy", type="primary", use_container_width=True): | |
st.code(prompt, language="") # This is just to show it was copied | |
with button_col2: | |
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 button_col3: | |
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() | |
# Sample prompts in 2 columns | |
st.markdown("<div class='section-header' style='font-size: 0.8rem;'>π Examples</div>", unsafe_allow_html=True) | |
sample_col1, sample_col2 = st.columns(2) | |
with sample_col1: | |
st.markdown(""" | |
<div style="background-color: #e6f3ff; border: 1px solid #b8daff; border-radius: 4px; padding: 4px; margin-bottom: 4px; font-size: 0.7em;"> | |
<b>π¨βπ« Teaching</b><pre style="white-space: pre-wrap; font-size: 0.75em; margin: 2px 0px;">Act as a π¨βπ« Teacher, use π Informative tone, Create a π Guide for π± Beginners. | |
It should be about Git version control. | |
Include practical examples. | |
Exclude advanced techniques. | |
Return as π Markdown.</pre> | |
</div> | |
""", unsafe_allow_html=True) | |
with sample_col2: | |
st.markdown(""" | |
<div style="background-color: #e6ffed; border: 1px solid #b8e6cc; border-radius: 4px; padding: 4px; margin-bottom: 4px; font-size: 0.7em;"> | |
<b>πΌ Business</b><pre style="white-space: pre-wrap; font-size: 0.75em; margin: 2px 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) | |
# Quick guide | |
st.markdown(""" | |
<div style="font-size: 0.7em; background-color: #f1f8ff; border-radius: 4px; padding: 4px; margin-top: 4px;"> | |
<b>Structure:</b> 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) |