Spaces:
Running
Running
File size: 3,944 Bytes
cb069fa 3e81833 cb069fa 8416685 3e81833 8416685 d39daa5 cb069fa 8416685 3e81833 35f1887 3e81833 8259245 3e81833 cb069fa 3e81833 8416685 3e81833 8416685 3e81833 d39daa5 3e81833 d39daa5 3e81833 8416685 3e81833 8416685 d39daa5 3e81833 d39daa5 3e81833 8416685 3e81833 6d829d8 3e81833 d39daa5 8416685 3e81833 8416685 d39daa5 8416685 3e81833 |
1 2 3 4 5 6 7 8 9 10 11 12 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import streamlit as st
import google.generativeai as genai
import time
# β
Streamlit Page Configuration for Hugging Face Spaces
st.set_page_config(page_title="PromptLab - AI Prompt Enhancer", layout="wide")
st.title("β‘ PromptLab - AI Prompt Enhancer")
# β
Retrieve the API key from Hugging Face secrets
GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
genai.configure(api_key=GOOGLE_API_KEY)
# β
Define Shinobi and Raikage Prompt Frameworks
SHINOBI_PROMPT = """You are an advanced prompt enhancer, specializing in creating structured, high-clarity prompts that optimize LLM performance.
Your task is to refine a given prompt using the **Shinobi framework**, ensuring the following principles:
β
**Concise & High-Density Prompting** β Remove fluff, keeping instructions clear and actionable (~250 words max).
β
**Explicit Role Definition** β Assign a role to the AI for better contextual grounding.
β
**Step-by-Step Clarity** β Break the task into structured sections, avoiding ambiguity.
β
**Defined Output Format** β Specify the response format (JSON, CSV, list, structured text, etc.).
β
**Zero Conflicting Instructions** β Ensure clarity in constraints (e.g., avoid βsimple yet comprehensiveβ).
β
**Optional: One-Shot Example** β Add a single example where relevant to guide the AI.
### **Enhance the following prompt using Shinobi principles:**
**Original Prompt:**
{user_prompt}
**Enhanced Shinobi Prompt:**
"""
RAIKAGE_PROMPT = """You are an elite AI strategist, specializing in designing execution-focused prompts that maximize LLM efficiency.
Your task is to refine a given prompt using the **Raikage framework**, ensuring the following principles:
β
**Precision & Depth** β Ensure expert-level guidance, reducing vagueness and ambiguity.
β
**Context & Execution Approach** β Include a structured methodology to solve the problem.
β
**Defined Output Format** β Specify exact structure (JSON, formatted text, markdown, tables, or code blocks).
β
**Edge Case Handling & Constraints** β Account for potential failures and model limitations.
β
**Optional: Few-Shot Prompting** β If beneficial, provide 1-2 high-quality examples for refinement.
β
**Complies with External Factors** β Adhere to best practices (e.g., ethical scraping, security policies).
### **Enhance the following prompt using Raikage principles:**
**Original Prompt:**
{user_prompt}
**Enhanced Raikage Prompt:**
"""
# β
Streamlit UI Components
st.subheader("π οΈ Choose Your Enhancement Mode:")
mode = st.radio("Select a mode:", ["π Shinobi", "β‘ Raikage"], horizontal=True)
user_prompt = st.text_area("βοΈ Enter your prompt:", height=150)
# β
Button to Enhance Prompt
if st.button("π Enhance Prompt"):
if not user_prompt.strip():
st.warning("β οΈ Please enter a prompt before enhancing!")
else:
with st.spinner("β‘ Enhancing your prompt... Please wait"):
time.sleep(1) # π Smooth UI transition
# Select the appropriate enhancement framework
if mode == "π Shinobi":
full_prompt = SHINOBI_PROMPT.format(user_prompt=user_prompt)
else:
full_prompt = RAIKAGE_PROMPT.format(user_prompt=user_prompt)
# β
Call Gemini API to Enhance the Prompt
try:
model = genai.GenerativeModel('gemini-2.0-flash')
response = model.generate_content(full_prompt)
# β
Display Enhanced Prompt
st.subheader("β¨ Enhanced Prompt:")
st.text_area("", response.text, height=200) # Read-only box
# β
Copy to Clipboard Button
st.code(response.text, language="markdown")
except Exception as e:
st.error(f"β API Error: {e}")
|