DrishtiSharma commited on
Commit
b737817
·
verified ·
1 Parent(s): ae79188

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -20,14 +20,22 @@ with st.sidebar:
20
  openai_key = os.getenv("OPENAI_API_KEY", "")
21
  serpapi_key = os.getenv("SERP_API_KEY", "")
22
 
23
- # Check if keys are set or allow the user to provide them
 
 
 
 
 
 
 
24
  if not openai_key:
25
- openai_key = st.sidebar.text_input("Missing: OpenAI API Key (OPENAI_API_KEY)", "")
26
  if not serpapi_key:
27
- serpapi_key = st.sidebar.text_input("Missing: SERP API Key (SERPAPI_KEY)", "")
28
 
29
- # Proceed only if both keys are set
30
- if openai_key and serpapi_key:
 
31
  # Main content
32
  if st.button("Find Similar Patents"):
33
  try:
@@ -75,5 +83,3 @@ if openai_key and serpapi_key:
75
  st.error(f"Key error encountered: {e}")
76
  except Exception as e:
77
  st.error(f"An error occurred: {e}")
78
- else:
79
- st.error("Please provide both OpenAI and SERP API keys in the sidebar to proceed.")
 
20
  openai_key = os.getenv("OPENAI_API_KEY", "")
21
  serpapi_key = os.getenv("SERP_API_KEY", "")
22
 
23
+ # Allow user to input missing keys
24
+ if not openai_key:
25
+ openai_key = st.text_input("Missing: OpenAI API Key (OPENAI_API_KEY)", "")
26
+ if not serpapi_key:
27
+ serpapi_key = st.text_input("Missing: SERP API Key (SERPAPI_KEY)", "")
28
+
29
+ # Check which API keys are missing and notify the user
30
+ missing_keys = []
31
  if not openai_key:
32
+ missing_keys.append("OpenAI API Key")
33
  if not serpapi_key:
34
+ missing_keys.append("SERP API Key")
35
 
36
+ if missing_keys:
37
+ st.error(f"Please provide the following missing key(s) in the sidebar: {', '.join(missing_keys)}")
38
+ else:
39
  # Main content
40
  if st.button("Find Similar Patents"):
41
  try:
 
83
  st.error(f"Key error encountered: {e}")
84
  except Exception as e:
85
  st.error(f"An error occurred: {e}")