ehagey commited on
Commit
3252680
·
verified ·
1 Parent(s): c3ac83b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -41
app.py CHANGED
@@ -23,46 +23,62 @@ import hashlib
23
 
24
  load_dotenv()
25
 
26
- def check_password():
27
- def password_entered():
28
- if hmac.compare_digest(st.session_state["username"], os.environ.get("STREAMLIT_USERNAME", "")) and \
29
- hmac.compare_digest(st.session_state["password"], os.environ.get("STREAMLIT_PASSWORD", "")):
30
- st.session_state["password_correct"] = True
31
- del st.session_state["password"]
32
- del st.session_state["username"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  else:
34
- st.session_state["password_correct"] = False
 
 
 
 
35
 
36
- if "password_correct" not in st.session_state:
37
- st.text_input("Username", key="username")
38
- st.text_input("Password", type="password", key="password")
39
- st.button("Login", on_click=password_entered)
40
- return False
41
-
42
- # Password correct
43
- elif not st.session_state["password_correct"]:
44
- st.text_input("Username", key="username")
45
- st.text_input("Password", type="password", key="password")
46
- st.button("Login", on_click=password_entered)
47
- st.error("Wrong Credentials Entered")
48
- return False
49
-
50
- return True
51
-
52
- togetherai_client = OpenAI(
53
- api_key=os.getenv('TOGETHERAI_API_KEY'),
54
- base_url="https://api.together.xyz/v1"
55
- )
56
-
57
- openai_client = OpenAI(
58
- api_key=os.getenv('OPENAI_API_KEY')
59
- )
60
-
61
- anthropic_client = Anthropic(
62
- api_key=os.getenv('ANTHROPIC_API_KEY')
63
- )
64
-
65
- genai.configure(api_key=os.environ["GEMINI_API_KEY"])
66
 
67
  MAX_CONCURRENT_CALLS = 5
68
  semaphore = threading.Semaphore(MAX_CONCURRENT_CALLS)
@@ -202,13 +218,21 @@ def process_evaluations_concurrently(questions, prompt_template, models_to_evalu
202
  progress_callback(current_iteration, total_iterations)
203
 
204
  return results
205
-
206
  def main():
207
  st.set_page_config(page_title="LLM Benchmarking in Healthcare", layout="wide")
208
 
209
- if not check_password():
210
- st.stop()
 
 
 
211
  st.title("LLM Benchmarking in Healthcare")
 
 
 
 
 
212
 
213
  if 'all_results' not in st.session_state:
214
  st.session_state.all_results = {}
 
23
 
24
  load_dotenv()
25
 
26
+ def setup_api_clients():
27
+ with st.sidebar:
28
+ st.title("API Configuration")
29
+
30
+ use_stored = st.checkbox("Use stored API keys")
31
+
32
+ if use_stored:
33
+ username = st.text_input("Username")
34
+ password = st.text_input("Password", type="password")
35
+
36
+ if st.button("Verify Credentials"):
37
+ if (hmac.compare_digest(username, os.environ.get("STREAMLIT_USERNAME", "")) and
38
+ hmac.compare_digest(password, os.environ.get("STREAMLIT_PASSWORD", ""))):
39
+ st.session_state.togetherai_client = OpenAI(
40
+ api_key=os.getenv('TOGETHERAI_API_KEY'),
41
+ base_url="https://api.together.xyz/v1"
42
+ )
43
+ st.session_state.openai_client = OpenAI(
44
+ api_key=os.getenv('OPENAI_API_KEY')
45
+ )
46
+ st.session_state.anthropic_client = Anthropic(
47
+ api_key=os.getenv('ANTHROPIC_API_KEY')
48
+ )
49
+ genai.configure(api_key=os.environ["GEMINI_API_KEY"])
50
+
51
+ st.session_state.api_configured = True
52
+ st.success("Successfully configured API clients with stored keys!")
53
+ else:
54
+ st.error("Invalid credentials. Please try again or use your own API keys.")
55
+ st.session_state.api_configured = False
56
  else:
57
+ st.subheader("Enter Your API Keys")
58
+ togetherai_key = st.text_input("Together AI API Key", type="password", key="togetherai_key")
59
+ openai_key = st.text_input("OpenAI API Key", type="password", key="openai_key")
60
+ anthropic_key = st.text_input("Anthropic API Key", type="password", key="anthropic_key")
61
+ gemini_key = st.text_input("Gemini API Key", type="password", key="gemini_key")
62
 
63
+ if st.button("Initialize with provided keys"):
64
+ try:
65
+ st.session_state.togetherai_client = OpenAI(
66
+ api_key=togetherai_key,
67
+ base_url="https://api.together.xyz/v1"
68
+ )
69
+ st.session_state.openai_client = OpenAI(
70
+ api_key=openai_key
71
+ )
72
+ st.session_state.anthropic_client = Anthropic(
73
+ api_key=anthropic_key
74
+ )
75
+ genai.configure(api_key=gemini_key)
76
+
77
+ st.session_state.api_configured = True
78
+ st.success("Successfully configured API clients with provided keys!")
79
+ except Exception as e:
80
+ st.error(f"Error initializing API clients: {str(e)}")
81
+ st.session_state.api_configured = False
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  MAX_CONCURRENT_CALLS = 5
84
  semaphore = threading.Semaphore(MAX_CONCURRENT_CALLS)
 
218
  progress_callback(current_iteration, total_iterations)
219
 
220
  return results
221
+
222
  def main():
223
  st.set_page_config(page_title="LLM Benchmarking in Healthcare", layout="wide")
224
 
225
+ if 'api_configured' not in st.session_state:
226
+ st.session_state.api_configured = False
227
+
228
+ setup_api_clients()
229
+
230
  st.title("LLM Benchmarking in Healthcare")
231
+
232
+ if not st.session_state.api_configured:
233
+ st.warning("Please configure API keys in the sidebar to proceed")
234
+ st.stop()
235
+
236
 
237
  if 'all_results' not in st.session_state:
238
  st.session_state.all_results = {}