Navya-Sree's picture
Create app.py
378f180 verified
raw
history blame
1.66 kB
import streamlit as st
import os
# Add this at the top of your app.py
st.set_page_config(page_title="Multi-Agent Code Assistant", page_icon="πŸ€–")
# API Key Setup
if 'api_key' not in st.session_state:
st.session_state.api_key = None
# Sidebar for API key
with st.sidebar:
st.header("πŸ”‘ API Configuration")
# Option 1: Use environment variable
env_key = os.getenv("OPENAI_API_KEY")
if env_key:
st.session_state.api_key = env_key
st.success("βœ… API key loaded from environment")
else:
# Option 2: User input
user_key = st.text_input(
"Enter OpenAI API Key:",
type="password",
help="Get your key from https://platform.openai.com/api-keys"
)
if user_key:
st.session_state.api_key = user_key
st.success("βœ… API key set!")
st.markdown("""
### How to get an API key:
1. Go to [OpenAI Platform](https://platform.openai.com/api-keys)
2. Click "Create new secret key"
3. Copy and paste it here
4. Your key is stored only in your browser session
""")
# Cost warning
st.warning("""
⚠️ **Cost Warning:**
- You're using YOUR OpenAI credits
- GPT-3.5-turbo: ~$0.0015 per 1K tokens
- Approx. 100 requests = $0.15
""")
# Check if API key is available
if not st.session_state.api_key:
st.error("πŸ” Please enter your OpenAI API key in the sidebar to continue.")
st.stop()
# Now initialize your agents with the API key
import openai
openai.api_key = st.session_state.api_key
# Rest of your app continues...