hruday96 commited on
Commit
8416685
Β·
verified Β·
1 Parent(s): 3e81833

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -2,15 +2,15 @@ import streamlit as st
2
  import google.generativeai as genai
3
  import time
4
 
5
- # Hugging Face Streamlit UI Configuration
6
- st.set_page_config(page_title="PromptLab", layout="wide")
7
  st.title("⚑ PromptLab - AI Prompt Enhancer")
8
 
9
- # Retrieve the API key from Streamlit secrets
10
  GOOGLE_API_KEY = st.secrets["GEMINI_API_KEY"]
11
  genai.configure(api_key=GOOGLE_API_KEY)
12
 
13
- # Define Shinobi and Raikage prompts
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 Layout
49
- mode = st.radio("πŸ”₯ Choose a mode:", ["πŸŒ€ Shinobi", "⚑ Raikage"], horizontal=True)
 
 
50
  user_prompt = st.text_area("✍️ Enter your prompt:", height=150)
51
 
52
- # Button to enhance prompt
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) # Simulate slight delay for better UI response
59
 
60
- # Select the correct system prompt
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
- # Initialize Gemini Model & Call API
67
  try:
68
  model = genai.GenerativeModel('gemini-pro')
69
  response = model.generate_content(full_prompt)
70
 
71
- # Display Output
72
  st.subheader("✨ Enhanced Prompt:")
73
- st.write(response.text)
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}")