Update app.py
Browse files
app.py
CHANGED
|
@@ -55,7 +55,7 @@ if not OPENAI_API_KEY:
|
|
| 55 |
|
| 56 |
# Instantiate the OpenAI client
|
| 57 |
try:
|
| 58 |
-
|
| 59 |
except Exception as e:
|
| 60 |
st.error(f"Failed to initialize OpenAI client: {e}")
|
| 61 |
logger.error(f"Failed to initialize OpenAI client: {e}")
|
|
@@ -763,6 +763,11 @@ def main():
|
|
| 763 |
|
| 764 |
def initialize_session_state():
|
| 765 |
"""Initialize necessary components in Streamlit's session state."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 766 |
if 'data' not in st.session_state:
|
| 767 |
st.session_state.data = {} # Store pd.DataFrame under a name
|
| 768 |
if 'data_ingestion' not in st.session_state:
|
|
@@ -781,14 +786,15 @@ def initialize_session_state():
|
|
| 781 |
st.session_state.dashboard = Dashboard()
|
| 782 |
if 'automated_reports' not in st.session_state:
|
| 783 |
st.session_state.automated_reports = AutomatedReports()
|
| 784 |
-
|
| 785 |
-
st.session_state.openai_client = st.session_state.get('openai_client', None)
|
| 786 |
if 'diagnosis_support' not in st.session_state:
|
| 787 |
st.session_state.diagnosis_support = SimpleDiagnosis(client=st.session_state.openai_client)
|
| 788 |
if 'knowledge_base' not in st.session_state:
|
| 789 |
st.session_state.knowledge_base = SimpleMedicalKnowledge(nlp_model=nlp, client=st.session_state.openai_client)
|
| 790 |
if 'pub_email' not in st.session_state:
|
| 791 |
-
|
|
|
|
|
|
|
| 792 |
|
| 793 |
def data_management_section():
|
| 794 |
"""Handles the data management section in the sidebar."""
|
|
@@ -1169,4 +1175,4 @@ def medical_knowledge_section():
|
|
| 1169 |
st.error("Please enter a medical question to search.")
|
| 1170 |
|
| 1171 |
if __name__ == "__main__":
|
| 1172 |
-
main()
|
|
|
|
| 55 |
|
| 56 |
# Instantiate the OpenAI client
|
| 57 |
try:
|
| 58 |
+
client = OpenAI(api_key=OPENAI_API_KEY) # Instantiating the client right here
|
| 59 |
except Exception as e:
|
| 60 |
st.error(f"Failed to initialize OpenAI client: {e}")
|
| 61 |
logger.error(f"Failed to initialize OpenAI client: {e}")
|
|
|
|
| 763 |
|
| 764 |
def initialize_session_state():
|
| 765 |
"""Initialize necessary components in Streamlit's session state."""
|
| 766 |
+
|
| 767 |
+
if 'openai_client' not in st.session_state:
|
| 768 |
+
# Instantiate the OpenAI client only if it doesn't exist in session state
|
| 769 |
+
st.session_state.openai_client = client # The one created earlier
|
| 770 |
+
|
| 771 |
if 'data' not in st.session_state:
|
| 772 |
st.session_state.data = {} # Store pd.DataFrame under a name
|
| 773 |
if 'data_ingestion' not in st.session_state:
|
|
|
|
| 786 |
st.session_state.dashboard = Dashboard()
|
| 787 |
if 'automated_reports' not in st.session_state:
|
| 788 |
st.session_state.automated_reports = AutomatedReports()
|
| 789 |
+
|
|
|
|
| 790 |
if 'diagnosis_support' not in st.session_state:
|
| 791 |
st.session_state.diagnosis_support = SimpleDiagnosis(client=st.session_state.openai_client)
|
| 792 |
if 'knowledge_base' not in st.session_state:
|
| 793 |
st.session_state.knowledge_base = SimpleMedicalKnowledge(nlp_model=nlp, client=st.session_state.openai_client)
|
| 794 |
if 'pub_email' not in st.session_state:
|
| 795 |
+
st.session_state.pub_email = PUB_EMAIL # Load PUB_EMAIL from environment variables
|
| 796 |
+
if 'treatment_recommendation' not in st.session_state:
|
| 797 |
+
st.session_state.treatment_recommendation = BasicTreatmentRecommendation()
|
| 798 |
|
| 799 |
def data_management_section():
|
| 800 |
"""Handles the data management section in the sidebar."""
|
|
|
|
| 1175 |
st.error("Please enter a medical question to search.")
|
| 1176 |
|
| 1177 |
if __name__ == "__main__":
|
| 1178 |
+
main()
|