hruday96 commited on
Commit
16e0909
Β·
verified Β·
1 Parent(s): 6d829d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -71
app.py CHANGED
@@ -1,81 +1,36 @@
1
  import streamlit as st
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
-
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
- βœ… **Precision & Depth** β†’ Ensure expert-level guidance, reducing vagueness and ambiguity.
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
- 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-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.")