Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,65 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
# Set page
|
4 |
st.set_page_config(page_title="AI Prompt Enhancer", layout="centered")
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
"""
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
.stTextArea, .stButton>button { background-color: #ffffff; color: #000000; }
|
26 |
-
.stButton>button { border-radius: 10px; font-size: 16px; padding: 10px 20px; }
|
27 |
-
</style>
|
28 |
-
"""
|
29 |
-
|
30 |
-
# Apply selected mode
|
31 |
-
st.markdown(dark_css if st.session_state.dark_mode else light_css, unsafe_allow_html=True)
|
32 |
-
|
33 |
-
# Header
|
34 |
st.title("β¨ AI Prompt Enhancer")
|
35 |
|
36 |
-
#
|
37 |
-
st.
|
38 |
|
39 |
-
#
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
#
|
43 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
"π§ Email & Outreach": ["Cold Emails", "Sales Pitches"],
|
49 |
-
"π Academic & Research": ["Essays", "Research Summaries"],
|
50 |
-
"π SEO Optimization": ["Keyword Rewrites", "Meta Descriptions"],
|
51 |
-
"π Creative Writing": ["Storytelling", "Poetry", "Social Media Posts"]
|
52 |
-
}
|
53 |
|
54 |
-
|
|
|
55 |
|
56 |
-
|
57 |
-
|
58 |
|
59 |
-
# Enhance Prompt Button
|
60 |
-
if st.button("π Enhance Prompt"):
|
61 |
-
st.write(f"πΉ **Enhanced Prompt for {selected_subcategory}:** [Prompt will be generated here]")
|
|
|
1 |
import streamlit as st
|
2 |
+
import openai
|
3 |
|
4 |
+
# Set Streamlit page configuration
|
5 |
st.set_page_config(page_title="AI Prompt Enhancer", layout="centered")
|
6 |
|
7 |
+
# OpenAI API Key (Store securely in Streamlit secrets)
|
8 |
+
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
|
9 |
+
|
10 |
+
# Initialize OpenAI Client
|
11 |
+
openai.api_key = OPENAI_API_KEY
|
12 |
+
|
13 |
+
# π Dictionary of Prompting Techniques
|
14 |
+
prompt_techniques = {
|
15 |
+
"π Chain of Thought (CoT)": "Breaks down reasoning into step-by-step logic.",
|
16 |
+
"π Few-Shot Learning": "Adds relevant examples for better AI understanding.",
|
17 |
+
"π§© ReAct (Reasoning + Acting)": "Improves AI decision-making with iterative steps.",
|
18 |
+
"π² Tree of Thoughts (ToT)": "Generates multiple possible reasoning paths.",
|
19 |
+
"π‘ Self-Consistency": "Reframes the prompt to generate diverse responses.",
|
20 |
+
"π HyDE (Hypothetical Doc Embeddings)": "Structures prompts for better retrieval-based outputs.",
|
21 |
+
"π Least-to-Most Prompting": "Breaks complex tasks into smaller, manageable steps.",
|
22 |
+
"π Graph Prompting": "Optimizes structured data queries and relationships."
|
23 |
+
}
|
24 |
+
|
25 |
+
# π― Title
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
st.title("β¨ AI Prompt Enhancer")
|
27 |
|
28 |
+
# π‘ Prompt Input Box
|
29 |
+
user_prompt = st.text_area("π‘ Prompt Idea Box", placeholder="Enter your prompt here...")
|
30 |
|
31 |
+
# π Dropdown for Selecting a Prompting Technique
|
32 |
+
selected_technique = st.selectbox(
|
33 |
+
"π οΈ Choose a Prompting Technique",
|
34 |
+
options=list(prompt_techniques.keys()),
|
35 |
+
format_func=lambda x: f"{x} - {prompt_techniques[x]}" # Display name + description
|
36 |
+
)
|
37 |
|
38 |
+
# π Enhance Prompt Button
|
39 |
+
if st.button("Enhance Prompt"):
|
40 |
+
if user_prompt.strip() == "":
|
41 |
+
st.warning("β οΈ Please enter a prompt before enhancing.")
|
42 |
+
else:
|
43 |
+
# Generate enhanced prompt using OpenAI API
|
44 |
+
try:
|
45 |
+
response = openai.ChatCompletion.create(
|
46 |
+
model="gpt-4o",
|
47 |
+
messages=[
|
48 |
+
{"role": "system", "content": f"Enhance this prompt using {selected_technique}."},
|
49 |
+
{"role": "user", "content": user_prompt}
|
50 |
+
],
|
51 |
+
temperature=0.7,
|
52 |
+
max_tokens=500
|
53 |
+
)
|
54 |
+
enhanced_prompt = response["choices"][0]["message"]["content"]
|
55 |
|
56 |
+
# π Display Enhanced Prompt
|
57 |
+
st.subheader("πΉ Enhanced Prompt:")
|
58 |
+
st.text_area(" ", value=enhanced_prompt, height=150)
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
# π Copy Button
|
61 |
+
st.button("π Copy Prompt", on_click=lambda: st.experimental_set_query_params(prompt=enhanced_prompt))
|
62 |
|
63 |
+
except Exception as e:
|
64 |
+
st.error(f"β Error: {str(e)}")
|
65 |
|
|
|
|
|
|