Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,72 +1,77 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
|
|
|
| 3 |
|
| 4 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
|
| 6 |
genai.configure(api_key=GOOGLE_API_KEY)
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
|
|
|
|
|
|
| 25 |
if mode == "π Shinobi":
|
| 26 |
-
|
| 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 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 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 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
|
| 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 |
|