Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,15 +2,15 @@ import streamlit as st
|
|
2 |
import google.generativeai as genai
|
3 |
import time
|
4 |
|
5 |
-
#
|
6 |
-
st.set_page_config(page_title="PromptLab", layout="wide")
|
7 |
st.title("β‘ PromptLab - AI Prompt Enhancer")
|
8 |
|
9 |
-
# Retrieve the API key from
|
10 |
GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
|
11 |
genai.configure(api_key=GOOGLE_API_KEY)
|
12 |
|
13 |
-
# Define Shinobi and Raikage
|
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 |
|
@@ -45,33 +45,37 @@ Your task is to refine a given prompt using the **Raikage framework**, ensuring
|
|
45 |
**Enhanced Raikage Prompt:**
|
46 |
"""
|
47 |
|
48 |
-
# Streamlit
|
49 |
-
|
|
|
|
|
50 |
user_prompt = st.text_area("βοΈ Enter your prompt:", height=150)
|
51 |
|
52 |
-
# Button to
|
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) #
|
59 |
|
60 |
-
# Select the
|
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 |
-
#
|
67 |
try:
|
68 |
model = genai.GenerativeModel('gemini-pro')
|
69 |
response = model.generate_content(full_prompt)
|
70 |
|
71 |
-
# Display
|
72 |
st.subheader("β¨ Enhanced Prompt:")
|
73 |
-
st.
|
74 |
|
|
|
|
|
|
|
75 |
except Exception as e:
|
76 |
st.error(f"β API Error: {e}")
|
77 |
-
|
|
|
2 |
import google.generativeai as genai
|
3 |
import time
|
4 |
|
5 |
+
# β
Streamlit Page Configuration for Hugging Face Spaces
|
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 |
+
# β
Define Shinobi and Raikage Prompt Frameworks
|
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 |
|
|
|
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 |
user_prompt = st.text_area("βοΈ Enter your prompt:", height=150)
|
53 |
|
54 |
+
# β
Button to Enhance Prompt
|
55 |
if st.button("π Enhance Prompt"):
|
56 |
if not user_prompt.strip():
|
57 |
st.warning("β οΈ Please enter a prompt before enhancing!")
|
58 |
else:
|
59 |
with st.spinner("β‘ Enhancing your prompt... Please wait"):
|
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-pro')
|
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}")
|
|