Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,81 +1,36 @@
|
|
1 |
import streamlit as st
|
2 |
import google.generativeai as genai
|
3 |
-
import time
|
4 |
|
5 |
-
#
|
6 |
-
st.set_page_config(page_title="PromptLab - AI Prompt Enhancer", layout="wide")
|
7 |
-
st.title("β‘ PromptLab - AI Prompt Enhancer")
|
8 |
-
|
9 |
-
# β
Retrieve the API key from Hugging Face secrets
|
10 |
GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
|
11 |
genai.configure(api_key=GOOGLE_API_KEY)
|
12 |
|
13 |
-
#
|
14 |
-
|
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 |
-
|
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 UI Components
|
49 |
-
st.subheader("π οΈ Choose Your Enhancement Mode:")
|
50 |
mode = st.radio("Select a mode:", ["π Shinobi", "β‘ Raikage"], horizontal=True)
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
else:
|
59 |
-
|
60 |
-
time.sleep(1) # π Smooth UI transition
|
61 |
-
|
62 |
-
# Select the appropriate enhancement framework
|
63 |
-
if mode == "π Shinobi":
|
64 |
-
full_prompt = SHINOBI_PROMPT.format(user_prompt=user_prompt)
|
65 |
-
else:
|
66 |
-
full_prompt = RAIKAGE_PROMPT.format(user_prompt=user_prompt)
|
67 |
-
|
68 |
-
# β
Call Gemini API to Enhance the Prompt
|
69 |
-
try:
|
70 |
-
model = genai.GenerativeModel('gemini-2.0-flash')
|
71 |
-
response = model.generate_content(full_prompt)
|
72 |
-
|
73 |
-
# β
Display Enhanced Prompt
|
74 |
-
st.subheader("β¨ Enhanced Prompt:")
|
75 |
-
st.text_area("", response.text, height=200) # Read-only box
|
76 |
-
|
77 |
-
# β
Copy to Clipboard Button
|
78 |
-
st.code(response.text, language="markdown")
|
79 |
-
|
80 |
-
except Exception as e:
|
81 |
-
st.error(f"β API Error: {e}")
|
|
|
1 |
import streamlit as st
|
2 |
import google.generativeai as genai
|
|
|
3 |
|
4 |
+
# Configure API Key
|
|
|
|
|
|
|
|
|
5 |
GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
|
6 |
genai.configure(api_key=GOOGLE_API_KEY)
|
7 |
|
8 |
+
# Streamlit App Layout
|
9 |
+
st.title('PromptLab')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Mode Selection (Shinobi & Raikage)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
mode = st.radio("Select a mode:", ["π Shinobi", "β‘ Raikage"], horizontal=True)
|
13 |
|
14 |
+
# User Input
|
15 |
+
user_prompt = st.text_area('Enter your prompt:')
|
16 |
+
|
17 |
+
# Function to Generate Enhanced Prompt
|
18 |
+
def generate_enhanced_prompt(user_prompt, mode):
|
19 |
+
if mode == "π Shinobi":
|
20 |
+
system_prompt = "You are an expert in structured prompt design. Refine the following prompt for clarity, conciseness, and structured output."
|
21 |
+
elif mode == "β‘ Raikage":
|
22 |
+
system_prompt = "You are a world-class AI strategist specializing in execution-focused prompts. Transform the following prompt for high-impact, expert-level results."
|
23 |
+
|
24 |
+
# Generate response using Gemini API
|
25 |
+
response = genai.generate_text(system_prompt + "\n\n" + user_prompt)
|
26 |
+
return response
|
27 |
+
|
28 |
+
# Process User Input
|
29 |
+
if st.button("Generate Enhanced Prompt"):
|
30 |
+
if user_prompt.strip():
|
31 |
+
with st.spinner("Enhancing prompt..."):
|
32 |
+
enhanced_prompt = generate_enhanced_prompt(user_prompt, mode)
|
33 |
+
st.subheader("Enhanced Prompt:")
|
34 |
+
st.code(enhanced_prompt, language='markdown')
|
35 |
else:
|
36 |
+
st.warning("Please enter a prompt before generating.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|