madhuroopa commited on
Commit
e9ec229
·
1 Parent(s): 0c9a4dd

added new application files

Browse files
Files changed (1) hide show
  1. app.py +34 -16
app.py CHANGED
@@ -1,7 +1,6 @@
1
  # Description: This file contains the main Streamlit application for the Resonate project.
2
- # Run command: streamlit run app.py to run the application
3
 
4
- ## testing
5
  import os
6
  import pandas as pd
7
  import streamlit as st
@@ -18,15 +17,17 @@ from src.utils.resonate_streamlitUtils import (
18
  transcript_text_editor_minutes_to_hhmmss,
19
  )
20
 
21
-
22
  def initialize_session_state():
23
  # Initialize API keys in session state if not present
24
  if "api_keys" not in ss:
25
  ss.api_keys = {}
26
- ss.api_keys["openai_api_key"] = os.environ.get("OPENAI_API_KEY")
27
- ss.api_keys["pinecone_api_key"] = os.environ.get("PINECONE_API_KEY")
28
- ss.api_keys["aws_access_key"] = os.environ.get("AWS_ACCESS_KEY")
29
- ss.api_keys["aws_secret_access_key"] = os.environ.get("AWS_SECRET_ACCESS_KEY")
 
 
 
30
  if "add_meeting" not in ss:
31
  ss.add_meeting = False
32
  if "Clustering_obj" not in ss:
@@ -38,7 +39,7 @@ def initialize_session_state():
38
  ss.transcript_text_editor = False
39
  if "meeting_name" not in ss:
40
  ss.meeting_name = ""
41
- if "df_transcript_speaker" not in ss:
42
  ss.df_transcript_speaker = pd.DataFrame()
43
  if "df_transcript_text" not in ss:
44
  ss.df_transcript_text = pd.DataFrame()
@@ -46,7 +47,7 @@ def initialize_session_state():
46
  ss.updated_transcript_df_to_embed = pd.DataFrame()
47
  if "chat_view" not in ss:
48
  ss.chat_view = True
49
- if "langchain_obj" not in ss:
50
  ss.langchain_obj = LangChain()
51
  if "query" not in ss:
52
  ss.query = ""
@@ -149,6 +150,9 @@ def api_keys_input():
149
  os.environ["AWS_SECRET_ACCESS_KEY"] = ss.api_keys[
150
  "aws_secret_access_key"
151
  ]
 
 
 
152
  st.rerun()
153
 
154
 
@@ -268,15 +272,20 @@ def transcript_text_editor():
268
 
269
 
270
  def init_streamlit():
271
- load_dotenv("./config/.env")
272
  initialize_session_state()
 
 
 
 
 
 
273
  # Set initial state of the sidebar
274
- if ss.api_keys["pinecone_api_key"] is not None:
275
- st.set_page_config(
276
- initial_sidebar_state="collapsed",
277
- layout="wide",
278
  )
279
  st.title("RESONATE")
 
280
  # Initializing sidebar and its components
281
  with st.sidebar:
282
  api_keys_input()
@@ -285,17 +294,26 @@ def init_streamlit():
285
  ss.chat_view = not ss.chat_view
286
  ss.transcript_speaker_editor = False
287
  ss.transcript_text_editor = False
288
- if ss.add_meeting:
 
 
 
 
 
 
289
  add_meeting()
290
  if ss.transcript_speaker_editor:
291
  transcript_speaker_editor()
292
  if ss.df_transcript_text is not None and ss.transcript_text_editor:
293
  transcript_text_editor()
294
- if ss.chat_view:
295
  chat_view() # Chat view
296
 
297
 
 
298
  if __name__ == "__main__":
 
 
299
  init_streamlit()
300
 
301
  # Test questions:
 
1
  # Description: This file contains the main Streamlit application for the Resonate project.
2
+ # Run command: streamlit run app.py
3
 
 
4
  import os
5
  import pandas as pd
6
  import streamlit as st
 
17
  transcript_text_editor_minutes_to_hhmmss,
18
  )
19
 
 
20
  def initialize_session_state():
21
  # Initialize API keys in session state if not present
22
  if "api_keys" not in ss:
23
  ss.api_keys = {}
24
+ ss.api_keys["openai_api_key"] = None
25
+ ss.api_keys["pinecone_api_key"] = None
26
+ ss.api_keys["aws_access_key"] = None
27
+ ss.api_keys["aws_secret_access_key"] = None
28
+
29
+ if "api_key_set" not in ss:
30
+ ss.api_key_set = False
31
  if "add_meeting" not in ss:
32
  ss.add_meeting = False
33
  if "Clustering_obj" not in ss:
 
39
  ss.transcript_text_editor = False
40
  if "meeting_name" not in ss:
41
  ss.meeting_name = ""
42
+ if "df_transcript_speaker" not in ss:
43
  ss.df_transcript_speaker = pd.DataFrame()
44
  if "df_transcript_text" not in ss:
45
  ss.df_transcript_text = pd.DataFrame()
 
47
  ss.updated_transcript_df_to_embed = pd.DataFrame()
48
  if "chat_view" not in ss:
49
  ss.chat_view = True
50
+ if "langchain_obj" not in ss and ss.api_key_set:
51
  ss.langchain_obj = LangChain()
52
  if "query" not in ss:
53
  ss.query = ""
 
150
  os.environ["AWS_SECRET_ACCESS_KEY"] = ss.api_keys[
151
  "aws_secret_access_key"
152
  ]
153
+
154
+ ss.api_key_set = True
155
+ print("API KEYS ARE: ", ss.api_keys)
156
  st.rerun()
157
 
158
 
 
272
 
273
 
274
  def init_streamlit():
 
275
  initialize_session_state()
276
+ if os.path.exists("./config/.env"):
277
+ load_dotenv("./config/.env")
278
+
279
+ else:
280
+ print(".env file does not exist, API keys must be set manually.")
281
+
282
  # Set initial state of the sidebar
283
+ st.set_page_config(
284
+ initial_sidebar_state="collapsed",
285
+ layout="wide",
 
286
  )
287
  st.title("RESONATE")
288
+
289
  # Initializing sidebar and its components
290
  with st.sidebar:
291
  api_keys_input()
 
294
  ss.chat_view = not ss.chat_view
295
  ss.transcript_speaker_editor = False
296
  ss.transcript_text_editor = False
297
+
298
+ if not ss.api_key_set:
299
+ st.header("Pre-requisites:")
300
+ st.write("Please set the API keys to enable the chat view.")
301
+ st.write("Please ensure that you have already run the 'pinecone_sample_dataloader.py'")
302
+
303
+ if ss.add_meeting and ss.api_key_set:
304
  add_meeting()
305
  if ss.transcript_speaker_editor:
306
  transcript_speaker_editor()
307
  if ss.df_transcript_text is not None and ss.transcript_text_editor:
308
  transcript_text_editor()
309
+ if ss.chat_view and ss.api_key_set:
310
  chat_view() # Chat view
311
 
312
 
313
+
314
  if __name__ == "__main__":
315
+ # Please ensure you have data loaded in Pinecone before running the Streamlit app
316
+ # Please refer https://github.com/SartajBhuvaji/Resonate/blob/master/init_one_time_utils/PREREQUISITE.md
317
  init_streamlit()
318
 
319
  # Test questions: