hruday96 commited on
Commit
3e81833
Β·
verified Β·
1 Parent(s): d39daa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -56
app.py CHANGED
@@ -1,72 +1,77 @@
1
  import streamlit as st
2
  import google.generativeai as genai
 
3
 
4
- # πŸ”‘ Load API Key from Streamlit Secrets
 
 
 
 
5
  GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
6
  genai.configure(api_key=GOOGLE_API_KEY)
7
 
8
- # 🎨 Streamlit UI Setup
9
- st.title("⚑ PromptLab – AI-Powered Prompt Enhancer")
10
- st.write("Enhance your prompts with **Shinobi** (Structured) or **Raikage** (Execution-Focused)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # 🎭 Mode Selection
13
- mode = st.radio("Select Mode:", ["πŸŒ€ Shinobi", "⚑ Raikage"], horizontal=True)
 
 
 
 
14
 
15
- # ✍️ User Input for Prompt
16
- user_prompt = st.text_area("Enter your prompt:")
 
17
 
18
- # πŸš€ Generate Enhanced Prompt
19
- if st.button("Enhance Prompt"):
 
 
 
 
 
 
 
20
  if not user_prompt.strip():
21
- st.warning("⚠️ Please enter a prompt before enhancing.")
22
  else:
23
- with st.spinner("Enhancing your prompt... ⚑"):
24
- # πŸ› οΈ Apply Shinobi or Raikage Framework
 
 
25
  if mode == "πŸŒ€ Shinobi":
26
- structured_prompt = f"""
27
- You are an advanced prompt enhancer, specializing in creating structured, high-clarity prompts that optimize LLM performance.
28
- Your task is to refine a given prompt using the **Shinobi framework**, ensuring:
29
-
30
- βœ… **Concise & High-Density Prompting** β†’ Remove fluff, keeping instructions clear and actionable.
31
- βœ… **Explicit Role Definition** β†’ Assign a role to the AI for better contextual grounding.
32
- βœ… **Step-by-Step Clarity** β†’ Break the task into structured sections.
33
- βœ… **Defined Output Format** β†’ Specify the response format.
34
-
35
- ### **Enhance the following prompt using Shinobi principles:**
36
-
37
- **Original Prompt:**
38
- {user_prompt}
39
-
40
- **Enhanced Shinobi Prompt:**
41
- """
42
  else:
43
- structured_prompt = f"""
44
- You are an elite AI strategist, specializing in designing execution-focused prompts that maximize LLM efficiency.
45
- Your task is to refine a given prompt using the **Raikage framework**, ensuring:
46
-
47
- βœ… **Precision & Depth** β†’ Ensure expert-level guidance, reducing vagueness.
48
- βœ… **Context & Execution Approach** β†’ Include a structured methodology.
49
- βœ… **Defined Output Format** β†’ Specify exact structure (JSON, markdown, tables, etc.).
50
- βœ… **Edge Case Handling & Constraints** β†’ Account for potential failures.
51
-
52
- ### **Enhance the following prompt using Raikage principles:**
53
 
54
- **Original Prompt:**
55
- {user_prompt}
 
56
 
57
- **Enhanced Raikage Prompt:**
58
- """
59
-
60
- # 🧠 Call Gemini API
61
- model = genai.GenerativeModel('gemini-pro')
62
- response = model.generate_content(structured_prompt)
63
-
64
- # πŸ“ Display Output
65
- enhanced_prompt = response.text.strip()
66
- st.subheader("πŸ”Ή Enhanced Prompt:")
67
- st.code(enhanced_prompt, language="markdown")
68
-
69
- # πŸ“‹ Copy Button
70
- st.button("πŸ“‹ Copy to Clipboard", on_click=lambda: st.session_state.update({"copied_text": enhanced_prompt}))
71
-
72
 
 
1
  import streamlit as st
2
  import google.generativeai as genai
3
+ import time
4
 
5
+ # Hugging Face Streamlit UI Configuration
6
+ st.set_page_config(page_title="PromptLab", layout="wide")
7
+ st.title("⚑ PromptLab - AI Prompt Enhancer")
8
+
9
+ # Retrieve the API key from Streamlit secrets
10
  GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
11
  genai.configure(api_key=GOOGLE_API_KEY)
12
 
13
+ # Define Shinobi and Raikage prompts
14
+ SHINOBI_PROMPT = """You are an advanced prompt enhancer, specializing in creating structured, high-clarity prompts that optimize LLM performance.
15
+ Your task is to refine a given prompt using the **Shinobi framework**, ensuring the following principles:
16
+
17
+ βœ… **Concise & High-Density Prompting** β†’ Remove fluff, keeping instructions clear and actionable (~250 words max).
18
+ βœ… **Explicit Role Definition** β†’ Assign a role to the AI for better contextual grounding.
19
+ βœ… **Step-by-Step Clarity** β†’ Break the task into structured sections, avoiding ambiguity.
20
+ βœ… **Defined Output Format** β†’ Specify the response format (JSON, CSV, list, structured text, etc.).
21
+ βœ… **Zero Conflicting Instructions** β†’ Ensure clarity in constraints (e.g., avoid β€œsimple yet comprehensive”).
22
+ βœ… **Optional: One-Shot Example** β†’ Add a single example where relevant to guide the AI.
23
+
24
+ ### **Enhance the following prompt using Shinobi principles:**
25
+ **Original Prompt:**
26
+ {user_prompt}
27
+
28
+ **Enhanced Shinobi Prompt:**
29
+ """
30
+
31
+ RAIKAGE_PROMPT = """You are an elite AI strategist, specializing in designing execution-focused prompts that maximize LLM efficiency.
32
+ Your task is to refine a given prompt using the **Raikage framework**, ensuring the following principles:
33
 
34
+ βœ… **Precision & Depth** β†’ Ensure expert-level guidance, reducing vagueness and ambiguity.
35
+ βœ… **Context & Execution Approach** β†’ Include a structured methodology to solve the problem.
36
+ βœ… **Defined Output Format** β†’ Specify exact structure (JSON, formatted text, markdown, tables, or code blocks).
37
+ βœ… **Edge Case Handling & Constraints** β†’ Account for potential failures and model limitations.
38
+ βœ… **Optional: Few-Shot Prompting** β†’ If beneficial, provide 1-2 high-quality examples for refinement.
39
+ βœ… **Complies with External Factors** β†’ Adhere to best practices (e.g., ethical scraping, security policies).
40
 
41
+ ### **Enhance the following prompt using Raikage principles:**
42
+ **Original Prompt:**
43
+ {user_prompt}
44
 
45
+ **Enhanced Raikage Prompt:**
46
+ """
47
+
48
+ # Streamlit Layout
49
+ mode = st.radio("πŸ”₯ Choose a mode:", ["πŸŒ€ Shinobi", "⚑ Raikage"], horizontal=True)
50
+ user_prompt = st.text_area("✍️ Enter your prompt:", height=150)
51
+
52
+ # Button to enhance prompt
53
+ if st.button("πŸš€ Enhance Prompt"):
54
  if not user_prompt.strip():
55
+ st.warning("⚠️ Please enter a prompt before enhancing!")
56
  else:
57
+ with st.spinner("⚑ Enhancing your prompt... Please wait"):
58
+ time.sleep(1) # Simulate slight delay for better UI response
59
+
60
+ # Select the correct system prompt
61
  if mode == "πŸŒ€ Shinobi":
62
+ full_prompt = SHINOBI_PROMPT.format(user_prompt=user_prompt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  else:
64
+ full_prompt = RAIKAGE_PROMPT.format(user_prompt=user_prompt)
65
+
66
+ # Initialize Gemini Model & Call API
67
+ try:
68
+ model = genai.GenerativeModel('gemini-pro')
69
+ response = model.generate_content(full_prompt)
 
 
 
 
70
 
71
+ # Display Output
72
+ st.subheader("✨ Enhanced Prompt:")
73
+ st.write(response.text)
74
 
75
+ except Exception as e:
76
+ st.error(f"❌ API Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
77