Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,22 +10,18 @@ import io
|
|
| 10 |
import yaml
|
| 11 |
|
| 12 |
def load_openai_key():
|
| 13 |
-
"""Load OpenAI API key from
|
| 14 |
try:
|
| 15 |
-
#
|
| 16 |
-
api_key = os.getenv('
|
| 17 |
|
| 18 |
-
# If not in env, try to get from Streamlit secrets
|
| 19 |
-
if not api_key and hasattr(st, 'secrets'):
|
| 20 |
-
api_key = st.secrets.get('OPENAI_API_KEY')
|
| 21 |
-
|
| 22 |
if not api_key:
|
| 23 |
-
st.error("OpenAI API key not found. Please
|
| 24 |
return None
|
| 25 |
|
| 26 |
return api_key
|
| 27 |
except Exception as e:
|
| 28 |
-
st.error(f"Error loading OpenAI API key: {str(e)}")
|
| 29 |
return None
|
| 30 |
|
| 31 |
def initialize_openai_client():
|
|
@@ -145,6 +141,10 @@ def main():
|
|
| 145 |
if 'chat_history' not in st.session_state:
|
| 146 |
st.session_state.chat_history = []
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
# Sidebar
|
| 149 |
with st.sidebar:
|
| 150 |
st.title("🚀 Chart Analysis AI")
|
|
@@ -157,8 +157,10 @@ def main():
|
|
| 157 |
if upload_option == "Upload Image":
|
| 158 |
uploaded_file = st.file_uploader("Upload your chart", type=["png", "jpg", "jpeg"])
|
| 159 |
elif upload_option == "Take Screenshot":
|
| 160 |
-
st.button("
|
| 161 |
-
|
|
|
|
|
|
|
| 162 |
|
| 163 |
# Analysis Options
|
| 164 |
st.subheader("Analysis Options")
|
|
|
|
| 10 |
import yaml
|
| 11 |
|
| 12 |
def load_openai_key():
|
| 13 |
+
"""Load OpenAI API key from HuggingFace secrets"""
|
| 14 |
try:
|
| 15 |
+
# Try to get from HuggingFace secrets via environment variable
|
| 16 |
+
api_key = os.getenv('OPENAI_API_KEY_HF')
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if not api_key:
|
| 19 |
+
st.error("OpenAI API key not found in HuggingFace secrets. Please ensure the secret is set as OPENAI_API_KEY_HF in your HuggingFace space.")
|
| 20 |
return None
|
| 21 |
|
| 22 |
return api_key
|
| 23 |
except Exception as e:
|
| 24 |
+
st.error(f"Error loading OpenAI API key from HuggingFace secrets: {str(e)}")
|
| 25 |
return None
|
| 26 |
|
| 27 |
def initialize_openai_client():
|
|
|
|
| 141 |
if 'chat_history' not in st.session_state:
|
| 142 |
st.session_state.chat_history = []
|
| 143 |
|
| 144 |
+
# Initialize variables
|
| 145 |
+
uploaded_file = None
|
| 146 |
+
screenshot_taken = False
|
| 147 |
+
|
| 148 |
# Sidebar
|
| 149 |
with st.sidebar:
|
| 150 |
st.title("🚀 Chart Analysis AI")
|
|
|
|
| 157 |
if upload_option == "Upload Image":
|
| 158 |
uploaded_file = st.file_uploader("Upload your chart", type=["png", "jpg", "jpeg"])
|
| 159 |
elif upload_option == "Take Screenshot":
|
| 160 |
+
if st.button("Take Screenshot", key="screenshot"):
|
| 161 |
+
st.info("Feature coming soon! For now, please use the Upload Image option.")
|
| 162 |
+
# Future screenshot implementation will go here
|
| 163 |
+
screenshot_taken = False
|
| 164 |
|
| 165 |
# Analysis Options
|
| 166 |
st.subheader("Analysis Options")
|