Spaces:
Sleeping
Sleeping
Remove API key text inputs, use environment variables instead
Browse files- streamlit_app.py +26 -27
streamlit_app.py
CHANGED
|
@@ -77,10 +77,12 @@ def generate_aoe_response(model, tokenizer, prompt, max_length=512):
|
|
| 77 |
except Exception as e:
|
| 78 |
return f"Error generating AoE response: {str(e)}"
|
| 79 |
|
| 80 |
-
def query_gpt4_api(prompt: str
|
| 81 |
-
"""Query GPT-4 API
|
|
|
|
|
|
|
| 82 |
if not api_key:
|
| 83 |
-
return "β GPT-4 API key not
|
| 84 |
|
| 85 |
try:
|
| 86 |
# This is a placeholder implementation - would need actual OpenAI API integration
|
|
@@ -88,10 +90,12 @@ def query_gpt4_api(prompt: str, api_key: Optional[str] = None) -> str:
|
|
| 88 |
except Exception as e:
|
| 89 |
return f"Error querying GPT-4: {str(e)}"
|
| 90 |
|
| 91 |
-
def query_gemini_api(prompt: str
|
| 92 |
-
"""Query Gemini API
|
|
|
|
|
|
|
| 93 |
if not api_key:
|
| 94 |
-
return "β Gemini API key not
|
| 95 |
|
| 96 |
try:
|
| 97 |
# This is a placeholder implementation - would need actual Google Gemini API integration
|
|
@@ -125,23 +129,9 @@ def main():
|
|
| 125 |
st.markdown("---")
|
| 126 |
st.subheader("π§ Configuration")
|
| 127 |
|
| 128 |
-
col1, col2
|
| 129 |
|
| 130 |
with col1:
|
| 131 |
-
openai_api_key = st.text_input(
|
| 132 |
-
"OpenAI API Key (for GPT-4)",
|
| 133 |
-
type="password",
|
| 134 |
-
help="Enter your OpenAI API key to enable GPT-4 responses"
|
| 135 |
-
)
|
| 136 |
-
|
| 137 |
-
with col2:
|
| 138 |
-
google_api_key = st.text_input(
|
| 139 |
-
"Google API Key (for Gemini)",
|
| 140 |
-
type="password",
|
| 141 |
-
help="Enter your Google API key to enable Gemini responses"
|
| 142 |
-
)
|
| 143 |
-
|
| 144 |
-
with col3:
|
| 145 |
max_length = st.slider(
|
| 146 |
"Max Response Length",
|
| 147 |
min_value=100,
|
|
@@ -151,6 +141,13 @@ def main():
|
|
| 151 |
help="Maximum length for generated responses"
|
| 152 |
)
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
# Main comparison interface
|
| 155 |
st.markdown("---")
|
| 156 |
st.subheader("π¬ Compare LLM Responses")
|
|
@@ -174,14 +171,14 @@ def main():
|
|
| 174 |
with col1:
|
| 175 |
st.markdown("### π€ GPT-4")
|
| 176 |
with st.spinner("Generating GPT-4 response..."):
|
| 177 |
-
gpt4_response = query_gpt4_api(user_prompt
|
| 178 |
st.markdown("**Response:**")
|
| 179 |
st.write(gpt4_response)
|
| 180 |
|
| 181 |
with col2:
|
| 182 |
st.markdown("### π Gemini")
|
| 183 |
with st.spinner("Generating Gemini response..."):
|
| 184 |
-
gemini_response = query_gemini_api(user_prompt
|
| 185 |
st.markdown("**Response:**")
|
| 186 |
st.write(gemini_response)
|
| 187 |
|
|
@@ -205,11 +202,13 @@ def main():
|
|
| 205 |
st.header("βΉοΈ Model Information")
|
| 206 |
|
| 207 |
st.markdown("**π€ GPT-4**")
|
| 208 |
-
|
|
|
|
| 209 |
st.write("Provider: OpenAI")
|
| 210 |
|
| 211 |
st.markdown("**π Gemini**")
|
| 212 |
-
|
|
|
|
| 213 |
st.write("Provider: Google")
|
| 214 |
|
| 215 |
st.markdown("**π° AOE (Local)**")
|
|
@@ -228,14 +227,14 @@ def main():
|
|
| 228 |
|
| 229 |
st.markdown("---")
|
| 230 |
st.markdown("**π Instructions:**")
|
| 231 |
-
st.markdown("1.
|
| 232 |
st.markdown("2. Enter your prompt in the text area")
|
| 233 |
st.markdown("3. Click 'Generate All Responses'")
|
| 234 |
st.markdown("4. Compare responses side by side")
|
| 235 |
|
| 236 |
st.markdown("---")
|
| 237 |
st.markdown("**β οΈ Notes:**")
|
| 238 |
-
st.markdown("- GPT-4 and Gemini require valid API keys")
|
| 239 |
st.markdown("- AOE model runs locally from outputs/student/")
|
| 240 |
st.markdown("- Responses are generated independently")
|
| 241 |
|
|
|
|
| 77 |
except Exception as e:
|
| 78 |
return f"Error generating AoE response: {str(e)}"
|
| 79 |
|
| 80 |
+
def query_gpt4_api(prompt: str) -> str:
|
| 81 |
+
"""Query GPT-4 API using environment variable for API key"""
|
| 82 |
+
api_key = os.getenv('OPENAI_API_KEY')
|
| 83 |
+
|
| 84 |
if not api_key:
|
| 85 |
+
return "β GPT-4 API key not found in environment variables. Please set OPENAI_API_KEY environment variable to use GPT-4."
|
| 86 |
|
| 87 |
try:
|
| 88 |
# This is a placeholder implementation - would need actual OpenAI API integration
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
return f"Error querying GPT-4: {str(e)}"
|
| 92 |
|
| 93 |
+
def query_gemini_api(prompt: str) -> str:
|
| 94 |
+
"""Query Gemini API using environment variable for API key"""
|
| 95 |
+
api_key = os.getenv('GOOGLE_API_KEY')
|
| 96 |
+
|
| 97 |
if not api_key:
|
| 98 |
+
return "β Gemini API key not found in environment variables. Please set GOOGLE_API_KEY environment variable to use Gemini."
|
| 99 |
|
| 100 |
try:
|
| 101 |
# This is a placeholder implementation - would need actual Google Gemini API integration
|
|
|
|
| 129 |
st.markdown("---")
|
| 130 |
st.subheader("π§ Configuration")
|
| 131 |
|
| 132 |
+
col1, col2 = st.columns(2)
|
| 133 |
|
| 134 |
with col1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
max_length = st.slider(
|
| 136 |
"Max Response Length",
|
| 137 |
min_value=100,
|
|
|
|
| 141 |
help="Maximum length for generated responses"
|
| 142 |
)
|
| 143 |
|
| 144 |
+
with col2:
|
| 145 |
+
# Display API key status
|
| 146 |
+
openai_key_status = "β
Found" if os.getenv('OPENAI_API_KEY') else "β Missing"
|
| 147 |
+
google_key_status = "β
Found" if os.getenv('GOOGLE_API_KEY') else "β Missing"
|
| 148 |
+
|
| 149 |
+
st.info(f"**API Key Status:**\n\nOpenAI API Key: {openai_key_status}\n\nGoogle API Key: {google_key_status}")
|
| 150 |
+
|
| 151 |
# Main comparison interface
|
| 152 |
st.markdown("---")
|
| 153 |
st.subheader("π¬ Compare LLM Responses")
|
|
|
|
| 171 |
with col1:
|
| 172 |
st.markdown("### π€ GPT-4")
|
| 173 |
with st.spinner("Generating GPT-4 response..."):
|
| 174 |
+
gpt4_response = query_gpt4_api(user_prompt)
|
| 175 |
st.markdown("**Response:**")
|
| 176 |
st.write(gpt4_response)
|
| 177 |
|
| 178 |
with col2:
|
| 179 |
st.markdown("### π Gemini")
|
| 180 |
with st.spinner("Generating Gemini response..."):
|
| 181 |
+
gemini_response = query_gemini_api(user_prompt)
|
| 182 |
st.markdown("**Response:**")
|
| 183 |
st.write(gemini_response)
|
| 184 |
|
|
|
|
| 202 |
st.header("βΉοΈ Model Information")
|
| 203 |
|
| 204 |
st.markdown("**π€ GPT-4**")
|
| 205 |
+
openai_status = "β
Configured" if os.getenv('OPENAI_API_KEY') else "β Environment variable OPENAI_API_KEY not set"
|
| 206 |
+
st.write(f"Status: {openai_status}")
|
| 207 |
st.write("Provider: OpenAI")
|
| 208 |
|
| 209 |
st.markdown("**π Gemini**")
|
| 210 |
+
google_status = "β
Configured" if os.getenv('GOOGLE_API_KEY') else "β Environment variable GOOGLE_API_KEY not set"
|
| 211 |
+
st.write(f"Status: {google_status}")
|
| 212 |
st.write("Provider: Google")
|
| 213 |
|
| 214 |
st.markdown("**π° AOE (Local)**")
|
|
|
|
| 227 |
|
| 228 |
st.markdown("---")
|
| 229 |
st.markdown("**π Instructions:**")
|
| 230 |
+
st.markdown("1. Set OPENAI_API_KEY and GOOGLE_API_KEY environment variables")
|
| 231 |
st.markdown("2. Enter your prompt in the text area")
|
| 232 |
st.markdown("3. Click 'Generate All Responses'")
|
| 233 |
st.markdown("4. Compare responses side by side")
|
| 234 |
|
| 235 |
st.markdown("---")
|
| 236 |
st.markdown("**β οΈ Notes:**")
|
| 237 |
+
st.markdown("- GPT-4 and Gemini require valid API keys in environment variables")
|
| 238 |
st.markdown("- AOE model runs locally from outputs/student/")
|
| 239 |
st.markdown("- Responses are generated independently")
|
| 240 |
|