hruday96 commited on
Commit
487e4c6
Β·
verified Β·
1 Parent(s): a78eca3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -49
app.py CHANGED
@@ -1,61 +1,65 @@
1
  import streamlit as st
 
2
 
3
- # Set page config
4
  st.set_page_config(page_title="AI Prompt Enhancer", layout="centered")
5
 
6
- # Dark/Light Mode Toggle
7
- if "dark_mode" not in st.session_state:
8
- st.session_state.dark_mode = False
9
-
10
- def toggle_mode():
11
- st.session_state.dark_mode = not st.session_state.dark_mode
12
-
13
- # Apply Custom Styling
14
- dark_css = """
15
- <style>
16
- body { background-color: #121212; color: #ffffff; }
17
- .stTextArea, .stButton>button { background-color: #1e1e1e; color: #ffffff; }
18
- .stButton>button { border-radius: 10px; font-size: 16px; padding: 10px 20px; }
19
- </style>
20
- """
21
-
22
- light_css = """
23
- <style>
24
- body { background-color: #f5f5f5; color: #000000; }
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
- # Dark Mode Toggle
37
- st.sidebar.button("πŸŒ™ Toggle Dark Mode" if not st.session_state.dark_mode else "β˜€οΈ Toggle Light Mode", on_click=toggle_mode)
38
 
39
- # Prompt Input Box
40
- prompt = st.text_area("πŸ’‘ Prompt Idea Box", placeholder="Type your prompt here...")
 
 
 
 
41
 
42
- # Category Selection
43
- st.subheader("πŸŽ›οΈ Select an Enhancement Type")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- categories = {
46
- "πŸ“œ Copywriting": ["Ad Copy", "Blog Intro", "Product Description"],
47
- "πŸ’» Code Generation": ["Python", "SQL", "Automation Scripts"],
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
- selected_category = st.selectbox("Choose a category:", list(categories.keys()))
 
55
 
56
- # Display subcategories as buttons
57
- selected_subcategory = st.radio("Choose an enhancement type:", categories[selected_category])
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