Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,23 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from openai import OpenAI
|
|
|
|
| 3 |
|
| 4 |
# 1. Configuration
|
| 5 |
st.set_page_config(page_title="High School Writing Coach", layout="wide")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# 2. System Prompt
|
| 16 |
# This enforces the "No Rewrite" rule.
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from openai import OpenAI
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
# 1. Configuration
|
| 6 |
st.set_page_config(page_title="High School Writing Coach", layout="wide")
|
| 7 |
|
| 8 |
+
# Get the API key from Environment Variables (HF Spaces) OR st.secrets (Local)
|
| 9 |
+
api_key = os.environ.get("OPENAI_API_KEY")
|
| 10 |
+
|
| 11 |
+
if not api_key:
|
| 12 |
+
try:
|
| 13 |
+
# Fallback for local development if using secrets.toml
|
| 14 |
+
api_key = st.secrets["OPENAI_API_KEY"]
|
| 15 |
+
except (FileNotFoundError, KeyError):
|
| 16 |
+
st.error("OpenAI API Key not found. Please add 'OPENAI_API_KEY' to your Hugging Face Space secrets.")
|
| 17 |
+
st.stop()
|
| 18 |
+
|
| 19 |
+
# Initialize client with the found key
|
| 20 |
+
client = OpenAI(api_key=api_key)
|
| 21 |
|
| 22 |
# 2. System Prompt
|
| 23 |
# This enforces the "No Rewrite" rule.
|