Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,72 @@
|
|
1 |
import streamlit as st
|
2 |
import google.generativeai as genai
|
3 |
|
4 |
-
# Streamlit
|
5 |
-
st.
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
9 |
|
10 |
-
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
|
15 |
-
#
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
|
21 |
-
# Display selected mode
|
22 |
-
st.write(f"You selected: {mode}")
|
23 |
|
|
|
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 |
|