DrishtiSharma commited on
Commit
c64ddc6
Β·
verified Β·
1 Parent(s): a44f104

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -2,20 +2,18 @@ import streamlit as st
2
  from swarm import Swarm, Agent
3
  from bs4 import BeautifulSoup
4
  import requests
5
- from huggingface_hub import HfApi
6
  import os
7
 
8
  # Function to fetch OpenAI API key from Hugging Face secrets
9
  def fetch_openai_api_key():
10
  try:
11
- # Replace 'OPENAI_API_KEY' with the exact key name you use in Hugging Face secrets
12
- api = HfApi()
13
- secret_key = api.get_secret("OPENAI_API_KEY")
14
  if secret_key:
15
  os.environ['OPENAI_API_KEY'] = secret_key
16
  st.success("OpenAI API Key retrieved and set successfully!")
17
  else:
18
- st.error("Could not retrieve the OpenAI API Key. Please check your Hugging Face secrets.")
19
  except Exception as e:
20
  st.error(f"Error retrieving OpenAI API Key: {str(e)}")
21
 
 
2
  from swarm import Swarm, Agent
3
  from bs4 import BeautifulSoup
4
  import requests
 
5
  import os
6
 
7
  # Function to fetch OpenAI API key from Hugging Face secrets
8
  def fetch_openai_api_key():
9
  try:
10
+ # Fetch the OpenAI API key using Streamlit's secrets
11
+ secret_key = st.secrets.get("OPENAI_API_KEY", "")
 
12
  if secret_key:
13
  os.environ['OPENAI_API_KEY'] = secret_key
14
  st.success("OpenAI API Key retrieved and set successfully!")
15
  else:
16
+ st.error("Could not retrieve the OpenAI API Key. Please check your Hugging Face secrets configuration.")
17
  except Exception as e:
18
  st.error(f"Error retrieving OpenAI API Key: {str(e)}")
19