Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,9 @@ import google.generativeai as genai
|
|
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 |
|
@@ -12,9 +15,25 @@ st.title('PromptLab')
|
|
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."
|
@@ -22,15 +41,20 @@ def generate_enhanced_prompt(user_prompt, mode):
|
|
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 |
-
|
26 |
-
return response
|
27 |
|
28 |
-
#
|
29 |
if st.button("Generate Enhanced Prompt"):
|
30 |
if user_prompt.strip():
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
35 |
else:
|
36 |
st.warning("Please enter a prompt before generating.")
|
|
|
|
|
|
|
|
5 |
GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
|
6 |
genai.configure(api_key=GOOGLE_API_KEY)
|
7 |
|
8 |
+
# Select Gemini Model
|
9 |
+
gemini_model = genai.GenerativeModel("gemini-2.0-flash")
|
10 |
+
|
11 |
# Streamlit App Layout
|
12 |
st.title('PromptLab')
|
13 |
|
|
|
15 |
mode = st.radio("Select a mode:", ["π Shinobi", "β‘ Raikage"], horizontal=True)
|
16 |
|
17 |
# User Input
|
18 |
+
st.subheader("Enter Your Prompt:")
|
19 |
user_prompt = st.text_area('Enter your prompt:')
|
20 |
|
21 |
# Function to Generate Enhanced Prompt
|
22 |
+
def get_gemini_response(prompt):
|
23 |
+
try:
|
24 |
+
response = gemini_model.generate_content(
|
25 |
+
prompt,
|
26 |
+
generation_config=genai.types.GenerationConfig(
|
27 |
+
temperature=0.7,
|
28 |
+
max_output_tokens=500,
|
29 |
+
candidate_count=1
|
30 |
+
)
|
31 |
+
)
|
32 |
+
return response.text if response else "Error: No response received."
|
33 |
+
except Exception as e:
|
34 |
+
return f"β Gemini error: {e}"
|
35 |
+
|
36 |
+
# Function to Format Prompt Based on Mode
|
37 |
def generate_enhanced_prompt(user_prompt, mode):
|
38 |
if mode == "π Shinobi":
|
39 |
system_prompt = "You are an expert in structured prompt design. Refine the following prompt for clarity, conciseness, and structured output."
|
|
|
41 |
system_prompt = "You are a world-class AI strategist specializing in execution-focused prompts. Transform the following prompt for high-impact, expert-level results."
|
42 |
|
43 |
# Generate response using Gemini API
|
44 |
+
return get_gemini_response(system_prompt + "\n\n" + user_prompt)
|
|
|
45 |
|
46 |
+
# Button to Submit the Prompt
|
47 |
if st.button("Generate Enhanced Prompt"):
|
48 |
if user_prompt.strip():
|
49 |
+
try:
|
50 |
+
with st.spinner("Enhancing prompt..."):
|
51 |
+
enhanced_prompt = generate_enhanced_prompt(user_prompt, mode)
|
52 |
+
st.subheader("Enhanced Prompt:")
|
53 |
+
st.write(enhanced_prompt) # Displaying the text from the response
|
54 |
+
except Exception as e:
|
55 |
+
st.error(f"Error: {e}")
|
56 |
else:
|
57 |
st.warning("Please enter a prompt before generating.")
|
58 |
+
|
59 |
+
# Footer
|
60 |
+
st.markdown("Built with π§ by Hruday & Google Gemini")
|