Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import random
|
|
5 |
# Set page configuration
|
6 |
st.set_page_config(page_title="ChatGPT Prompt Generator", page_icon="๐ง ", layout="wide")
|
7 |
|
8 |
-
# Custom CSS for
|
9 |
st.markdown("""
|
10 |
<style>
|
11 |
.main {background-color: #f8f9fa;}
|
@@ -13,39 +13,38 @@ st.markdown("""
|
|
13 |
border-radius: 4px;
|
14 |
padding: 2px 4px;
|
15 |
font-size: 0.75em;
|
16 |
-
min-height: 0px;
|
17 |
margin: 1px;
|
18 |
-
|
19 |
}
|
20 |
.stButton button:hover {background-color: #e9ecef;}
|
21 |
-
div[data-testid="stVerticalBlock"] {gap: 0.
|
22 |
div[data-testid="stHorizontalBlock"] {gap: 0.3rem;}
|
23 |
.stTextArea textarea, .stTextInput input {
|
24 |
padding: 0.2rem;
|
25 |
font-size: 0.8em;
|
26 |
-
min-height: 0px;
|
27 |
}
|
28 |
h1, h2, h3 {margin-top: 0; margin-bottom: 0.1rem; font-size: 0.9rem;}
|
29 |
p, div {margin-bottom: 0.1rem; font-size: 0.8rem;}
|
30 |
-
.category-
|
31 |
background-color: white;
|
32 |
border: 1px solid #e6e6e6;
|
33 |
border-radius: 4px;
|
34 |
padding: 5px;
|
35 |
margin-bottom: 5px;
|
36 |
}
|
37 |
-
.
|
38 |
font-weight: bold;
|
39 |
-
font-size: 0.
|
40 |
-
margin-bottom: 0.1rem;
|
41 |
color: #333;
|
42 |
-
|
43 |
-
|
|
|
44 |
}
|
45 |
-
.
|
46 |
display: flex;
|
47 |
flex-wrap: wrap;
|
48 |
gap: 2px;
|
|
|
49 |
}
|
50 |
.prompt-display {
|
51 |
background-color: #ffffff;
|
@@ -56,16 +55,6 @@ st.markdown("""
|
|
56 |
font-size: 0.8em;
|
57 |
white-space: pre-wrap;
|
58 |
}
|
59 |
-
.sample-prompt {
|
60 |
-
font-size: 0.7em;
|
61 |
-
padding: 3px;
|
62 |
-
border-radius: 4px;
|
63 |
-
margin-bottom: 3px;
|
64 |
-
}
|
65 |
-
.emoji {font-size: 0.9em;}
|
66 |
-
.btn-group {
|
67 |
-
margin-bottom: 0px;
|
68 |
-
}
|
69 |
</style>
|
70 |
""", unsafe_allow_html=True)
|
71 |
|
@@ -133,14 +122,13 @@ data = {
|
|
133 |
]
|
134 |
}
|
135 |
|
136 |
-
# Function to create buttons for a category
|
137 |
-
def
|
138 |
-
st.markdown(f""
|
139 |
-
<div class="category-
|
140 |
-
|
141 |
-
<div class="button-flex-container">
|
142 |
-
""", unsafe_allow_html=True)
|
143 |
|
|
|
144 |
for i, item in enumerate(items):
|
145 |
key = f"{category_name.lower().replace(' ', '_')}_{i}"
|
146 |
is_selected = st.session_state.selections.get(category_name.lower().replace(' ', '_')) == item
|
@@ -148,49 +136,57 @@ def create_category_container(category_name, items, emoji_prefix=""):
|
|
148 |
|
149 |
if st.button(f"{item['emoji']} {item['name']}", key=key,
|
150 |
help=f"Select {item['name']}",
|
151 |
-
type=button_type
|
152 |
-
use_container_width=False):
|
153 |
st.session_state.selections[category_name.lower().replace(' ', '_')] = item
|
154 |
st.experimental_rerun()
|
155 |
|
156 |
-
st.markdown(
|
157 |
|
158 |
# Minimal header
|
159 |
-
st.markdown("<h2 style='text-align: center; font-size: 1.2rem;'
|
160 |
|
161 |
-
# Main layout with columns
|
162 |
left_col, right_col = st.columns([3, 1])
|
163 |
|
164 |
with left_col:
|
165 |
-
#
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
|
174 |
-
# Add text inputs
|
175 |
-
st.markdown('<div class="category-
|
176 |
-
st.markdown('<div class="
|
177 |
|
178 |
-
#
|
179 |
-
st.session_state.selections['about'] = st.text_input("
|
180 |
value=st.session_state.selections['about'],
|
181 |
-
placeholder="Enter what the content should be about"
|
|
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
190 |
|
191 |
-
|
|
|
192 |
value=st.session_state.selections['input_data'],
|
193 |
placeholder="Enter any specific information to use",
|
|
|
194 |
height=60)
|
195 |
|
196 |
st.markdown('</div>', unsafe_allow_html=True)
|
@@ -224,19 +220,20 @@ It should be about {sel['about']}."""
|
|
224 |
else:
|
225 |
prompt = "Select all required components and provide a topic."
|
226 |
|
227 |
-
|
228 |
-
st.markdown('<div class="
|
|
|
229 |
st.markdown('<div class="prompt-display">', unsafe_allow_html=True)
|
230 |
st.write(prompt)
|
231 |
st.markdown('</div>', unsafe_allow_html=True)
|
232 |
|
233 |
-
# Action buttons
|
234 |
-
|
235 |
-
with
|
236 |
if st.button("๐ Copy", type="primary", use_container_width=True):
|
237 |
st.code(prompt, language="")
|
238 |
|
239 |
-
with
|
240 |
if st.button("๐ Reset", type="secondary", use_container_width=True):
|
241 |
for key in st.session_state.selections:
|
242 |
if key in ['about', 'inclusion', 'exclusion', 'input_data']:
|
@@ -245,7 +242,7 @@ It should be about {sel['about']}."""
|
|
245 |
st.session_state.selections[key] = None
|
246 |
st.experimental_rerun()
|
247 |
|
248 |
-
with
|
249 |
if st.button("๐ฒ Random", type="secondary", use_container_width=True):
|
250 |
for category in ['role', 'tone', 'instruction', 'length', 'content_type', 'audience', 'format']:
|
251 |
st.session_state.selections[category] = random.choice(data[category+'s'])
|
@@ -253,9 +250,9 @@ It should be about {sel['about']}."""
|
|
253 |
|
254 |
st.markdown('</div>', unsafe_allow_html=True)
|
255 |
|
256 |
-
# Sample prompts
|
257 |
-
st.markdown('<div class="category-
|
258 |
-
st.markdown('<div class="
|
259 |
|
260 |
st.markdown("""
|
261 |
<div style="background-color: #e6f3ff; border: 1px solid #b8daff; border-radius: 4px; padding: 4px; margin-bottom: 4px; font-size: 0.7em;">
|
@@ -267,9 +264,7 @@ Exclude advanced techniques.
|
|
267 |
|
268 |
Return as ๐ Markdown.</pre>
|
269 |
</div>
|
270 |
-
""", unsafe_allow_html=True)
|
271 |
|
272 |
-
st.markdown("""
|
273 |
<div style="background-color: #e6ffed; border: 1px solid #b8e6cc; border-radius: 4px; padding: 4px; margin-bottom: 4px; font-size: 0.7em;">
|
274 |
<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.
|
275 |
|
@@ -279,10 +274,7 @@ Exclude technical details.
|
|
279 |
|
280 |
Return as ๐ Plain Text.</pre>
|
281 |
</div>
|
282 |
-
""", unsafe_allow_html=True)
|
283 |
|
284 |
-
# Structure guide
|
285 |
-
st.markdown("""
|
286 |
<div style="font-size: 0.7em; background-color: #f1f8ff; border-radius: 4px; padding: 4px; margin-top: 4px;">
|
287 |
<b>Structure:</b><br>
|
288 |
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>
|
|
|
5 |
# Set page configuration
|
6 |
st.set_page_config(page_title="ChatGPT Prompt Generator", page_icon="๐ง ", layout="wide")
|
7 |
|
8 |
+
# Custom CSS for horizontal button rows
|
9 |
st.markdown("""
|
10 |
<style>
|
11 |
.main {background-color: #f8f9fa;}
|
|
|
13 |
border-radius: 4px;
|
14 |
padding: 2px 4px;
|
15 |
font-size: 0.75em;
|
|
|
16 |
margin: 1px;
|
17 |
+
white-space: nowrap;
|
18 |
}
|
19 |
.stButton button:hover {background-color: #e9ecef;}
|
20 |
+
div[data-testid="stVerticalBlock"] {gap: 0.2rem;}
|
21 |
div[data-testid="stHorizontalBlock"] {gap: 0.3rem;}
|
22 |
.stTextArea textarea, .stTextInput input {
|
23 |
padding: 0.2rem;
|
24 |
font-size: 0.8em;
|
|
|
25 |
}
|
26 |
h1, h2, h3 {margin-top: 0; margin-bottom: 0.1rem; font-size: 0.9rem;}
|
27 |
p, div {margin-bottom: 0.1rem; font-size: 0.8rem;}
|
28 |
+
.category-row {
|
29 |
background-color: white;
|
30 |
border: 1px solid #e6e6e6;
|
31 |
border-radius: 4px;
|
32 |
padding: 5px;
|
33 |
margin-bottom: 5px;
|
34 |
}
|
35 |
+
.category-label {
|
36 |
font-weight: bold;
|
37 |
+
font-size: 0.85rem;
|
|
|
38 |
color: #333;
|
39 |
+
margin-right: 5px;
|
40 |
+
margin-bottom: 3px;
|
41 |
+
display: block;
|
42 |
}
|
43 |
+
.horizontal-buttons {
|
44 |
display: flex;
|
45 |
flex-wrap: wrap;
|
46 |
gap: 2px;
|
47 |
+
align-items: center;
|
48 |
}
|
49 |
.prompt-display {
|
50 |
background-color: #ffffff;
|
|
|
55 |
font-size: 0.8em;
|
56 |
white-space: pre-wrap;
|
57 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
</style>
|
59 |
""", unsafe_allow_html=True)
|
60 |
|
|
|
122 |
]
|
123 |
}
|
124 |
|
125 |
+
# Function to create a row of buttons for a category
|
126 |
+
def create_horizontal_button_row(category_name, items, emoji_prefix=""):
|
127 |
+
st.markdown(f'<div class="category-row">', unsafe_allow_html=True)
|
128 |
+
st.markdown(f'<div class="category-label">{emoji_prefix} {category_name}:</div>', unsafe_allow_html=True)
|
129 |
+
st.markdown('<div class="horizontal-buttons">', unsafe_allow_html=True)
|
|
|
|
|
130 |
|
131 |
+
# Create buttons in streamlit (can't be created inside HTML)
|
132 |
for i, item in enumerate(items):
|
133 |
key = f"{category_name.lower().replace(' ', '_')}_{i}"
|
134 |
is_selected = st.session_state.selections.get(category_name.lower().replace(' ', '_')) == item
|
|
|
136 |
|
137 |
if st.button(f"{item['emoji']} {item['name']}", key=key,
|
138 |
help=f"Select {item['name']}",
|
139 |
+
type=button_type):
|
|
|
140 |
st.session_state.selections[category_name.lower().replace(' ', '_')] = item
|
141 |
st.experimental_rerun()
|
142 |
|
143 |
+
st.markdown('</div></div>', unsafe_allow_html=True)
|
144 |
|
145 |
# Minimal header
|
146 |
+
st.markdown("<h2 style='text-align: center; font-size: 1.2rem;'>๐ง ChatGPT Prompt Generator</h2>", unsafe_allow_html=True)
|
147 |
|
148 |
+
# Main layout with two columns
|
149 |
left_col, right_col = st.columns([3, 1])
|
150 |
|
151 |
with left_col:
|
152 |
+
# Create a horizontal row of buttons for each category
|
153 |
+
create_horizontal_button_row("Role", data['roles'], "๐ค")
|
154 |
+
create_horizontal_button_row("Tone", data['tones'], "๐ญ")
|
155 |
+
create_horizontal_button_row("Instruction", data['instructions'], "๐")
|
156 |
+
create_horizontal_button_row("Length", data['lengths'], "๐")
|
157 |
+
create_horizontal_button_row("Content Type", data['content_types'], "๐")
|
158 |
+
create_horizontal_button_row("Audience", data['audiences'], "๐ฅ")
|
159 |
+
create_horizontal_button_row("Format", data['formats'], "๐")
|
160 |
|
161 |
+
# Add text inputs in a row container
|
162 |
+
st.markdown('<div class="category-row">', unsafe_allow_html=True)
|
163 |
+
st.markdown('<div class="category-label">๐ Details:</div>', unsafe_allow_html=True)
|
164 |
|
165 |
+
# Topic input
|
166 |
+
st.session_state.selections['about'] = st.text_input("Topic",
|
167 |
value=st.session_state.selections['about'],
|
168 |
+
placeholder="Enter what the content should be about",
|
169 |
+
label_visibility="collapsed")
|
170 |
|
171 |
+
# Two fields in one row
|
172 |
+
col1, col2 = st.columns(2)
|
173 |
+
with col1:
|
174 |
+
st.session_state.selections['inclusion'] = st.text_input("Include",
|
175 |
+
value=st.session_state.selections['inclusion'],
|
176 |
+
placeholder="What to include",
|
177 |
+
label_visibility="collapsed")
|
178 |
|
179 |
+
with col2:
|
180 |
+
st.session_state.selections['exclusion'] = st.text_input("Exclude",
|
181 |
+
value=st.session_state.selections['exclusion'],
|
182 |
+
placeholder="What to exclude",
|
183 |
+
label_visibility="collapsed")
|
184 |
|
185 |
+
# Input data
|
186 |
+
st.session_state.selections['input_data'] = st.text_area("Input Data",
|
187 |
value=st.session_state.selections['input_data'],
|
188 |
placeholder="Enter any specific information to use",
|
189 |
+
label_visibility="collapsed",
|
190 |
height=60)
|
191 |
|
192 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
220 |
else:
|
221 |
prompt = "Select all required components and provide a topic."
|
222 |
|
223 |
+
# Display the generated prompt
|
224 |
+
st.markdown('<div class="category-row">', unsafe_allow_html=True)
|
225 |
+
st.markdown('<div class="category-label">๐ฎ Generated Prompt:</div>', unsafe_allow_html=True)
|
226 |
st.markdown('<div class="prompt-display">', unsafe_allow_html=True)
|
227 |
st.write(prompt)
|
228 |
st.markdown('</div>', unsafe_allow_html=True)
|
229 |
|
230 |
+
# Action buttons in a row
|
231 |
+
col1, col2, col3 = st.columns(3)
|
232 |
+
with col1:
|
233 |
if st.button("๐ Copy", type="primary", use_container_width=True):
|
234 |
st.code(prompt, language="")
|
235 |
|
236 |
+
with col2:
|
237 |
if st.button("๐ Reset", type="secondary", use_container_width=True):
|
238 |
for key in st.session_state.selections:
|
239 |
if key in ['about', 'inclusion', 'exclusion', 'input_data']:
|
|
|
242 |
st.session_state.selections[key] = None
|
243 |
st.experimental_rerun()
|
244 |
|
245 |
+
with col3:
|
246 |
if st.button("๐ฒ Random", type="secondary", use_container_width=True):
|
247 |
for category in ['role', 'tone', 'instruction', 'length', 'content_type', 'audience', 'format']:
|
248 |
st.session_state.selections[category] = random.choice(data[category+'s'])
|
|
|
250 |
|
251 |
st.markdown('</div>', unsafe_allow_html=True)
|
252 |
|
253 |
+
# Sample prompts and structure guide
|
254 |
+
st.markdown('<div class="category-row">', unsafe_allow_html=True)
|
255 |
+
st.markdown('<div class="category-label">๐ Examples:</div>', unsafe_allow_html=True)
|
256 |
|
257 |
st.markdown("""
|
258 |
<div style="background-color: #e6f3ff; border: 1px solid #b8daff; border-radius: 4px; padding: 4px; margin-bottom: 4px; font-size: 0.7em;">
|
|
|
264 |
|
265 |
Return as ๐ Markdown.</pre>
|
266 |
</div>
|
|
|
267 |
|
|
|
268 |
<div style="background-color: #e6ffed; border: 1px solid #b8e6cc; border-radius: 4px; padding: 4px; margin-bottom: 4px; font-size: 0.7em;">
|
269 |
<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.
|
270 |
|
|
|
274 |
|
275 |
Return as ๐ Plain Text.</pre>
|
276 |
</div>
|
|
|
277 |
|
|
|
|
|
278 |
<div style="font-size: 0.7em; background-color: #f1f8ff; border-radius: 4px; padding: 4px; margin-top: 4px;">
|
279 |
<b>Structure:</b><br>
|
280 |
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>
|