Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,82 @@
|
|
| 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 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
# Button to Submit the Prompt
|
| 40 |
if st.button("Generate Enhanced Prompt"):
|
| 41 |
-
if
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
st.error(f"Error: {e}")
|
| 49 |
-
else:
|
| 50 |
-
st.warning("Please enter a prompt before generating.")
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import google.generativeai as genai
|
| 3 |
|
| 4 |
+
# Streamlit app layout
|
| 5 |
+
st.title('PromptLab')
|
| 6 |
+
|
| 7 |
+
# Create two columns for the Shinobi and Raikage buttons
|
| 8 |
+
col1, col2 = st.columns(2)
|
| 9 |
+
|
| 10 |
+
mode = st.radio("Choose a mode:", ["Shinobi", "Raikage"], horizontal=True)
|
| 11 |
+
|
| 12 |
+
# Retrieve the API key from Streamlit secrets
|
| 13 |
GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
|
| 14 |
+
|
| 15 |
+
# Configure the Google Generative AI API with your API key
|
| 16 |
genai.configure(api_key=GOOGLE_API_KEY)
|
| 17 |
|
| 18 |
+
# Input field for the blog topic
|
| 19 |
+
topic = st.text_area('Enter your prompt:')
|
| 20 |
|
| 21 |
+
# Display selected mode
|
| 22 |
+
st.write(f"You selected: {mode}")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# Shinobi and Raikage templates
|
| 26 |
+
SHINOBI_TEMPLATE = """
|
| 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 the following principles:
|
| 29 |
+
|
| 30 |
+
β
**Concise & High-Density Prompting** β Remove fluff, keeping instructions clear and actionable (~250 words max).
|
| 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, avoiding ambiguity.
|
| 33 |
+
β
**Defined Output Format** β Specify the response format (JSON, CSV, list, structured text, etc.).
|
| 34 |
+
β
**Zero Conflicting Instructions** β Ensure clarity in constraints (e.g., avoid βsimple yet comprehensiveβ).
|
| 35 |
+
β
**Optional: One-Shot Example** β Add a single example where relevant to guide the AI.
|
| 36 |
|
| 37 |
+
### **Enhance the following prompt using Shinobi principles:**
|
| 38 |
+
**Original Prompt:**
|
| 39 |
+
{user_prompt}
|
| 40 |
+
|
| 41 |
+
**Enhanced Shinobi Prompt:**
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
RAIKAGE_TEMPLATE = """
|
| 45 |
+
You are an elite AI strategist, specializing in designing execution-focused prompts that maximize LLM efficiency.
|
| 46 |
+
Your task is to refine a given prompt using the **Raikage framework**, ensuring the following principles:
|
| 47 |
+
|
| 48 |
+
β
**Precision & Depth** β Ensure expert-level guidance, reducing vagueness and ambiguity.
|
| 49 |
+
β
**Context & Execution Approach** β Include a structured methodology to solve the problem.
|
| 50 |
+
β
**Defined Output Format** β Specify exact structure (JSON, formatted text, markdown, tables, or code blocks).
|
| 51 |
+
β
**Edge Case Handling & Constraints** β Account for potential failures and model limitations.
|
| 52 |
+
β
**Optional: Few-Shot Prompting** β If beneficial, provide 1-2 high-quality examples for refinement.
|
| 53 |
+
β
**Complies with External Factors** β Adhere to best practices (e.g., ethical scraping, security policies).
|
| 54 |
+
|
| 55 |
+
### **Enhance the following prompt using Raikage principles:**
|
| 56 |
+
**Original Prompt:**
|
| 57 |
+
{user_prompt}
|
| 58 |
+
|
| 59 |
+
**Enhanced Raikage Prompt:**
|
| 60 |
+
"""
|
|
|
|
|
|
|
| 61 |
if st.button("Generate Enhanced Prompt"):
|
| 62 |
+
if topic.strip():
|
| 63 |
+
with st.spinner("Enhancing your prompt..."):
|
| 64 |
+
# Choose the template based on the selected mode
|
| 65 |
+
if mode == "Shinobi":
|
| 66 |
+
prompt = SHINOBI_TEMPLATE.format(user_prompt=topic)
|
| 67 |
+
else:
|
| 68 |
+
prompt = RAIKAGE_TEMPLATE.format(user_prompt=topic)
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
# Initialize the generative model
|
| 71 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 72 |
+
|
| 73 |
+
# Generate enhanced prompt
|
| 74 |
+
try:
|
| 75 |
+
response = model.generate_content(prompt)
|
| 76 |
+
enhanced_prompt = response.text # Extract the response text
|
| 77 |
+
st.subheader("πΉ Enhanced Prompt:")
|
| 78 |
+
st.code(enhanced_prompt, language="markdown")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
st.error(f"β Error generating enhanced prompt: {e}")
|
| 81 |
+
else:
|
| 82 |
+
st.warning("β οΈ Please enter a prompt before generating.")
|