Update app.py
Browse files
app.py
CHANGED
@@ -36,10 +36,15 @@ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
|
36 |
try:
|
37 |
nlp = spacy.load("en_core_web_sm")
|
38 |
except OSError:
|
|
|
39 |
st.write("Downloading en_core_web_sm spaCy model...")
|
40 |
spacy.cli.download("en_core_web_sm")
|
41 |
nlp = spacy.load("en_core_web_sm")
|
42 |
|
|
|
|
|
|
|
|
|
43 |
# ---------------------- Base Classes and Schemas ---------------------------
|
44 |
|
45 |
class ResearchInput(BaseModel):
|
@@ -244,8 +249,8 @@ class ClinicalRulesEngine:
|
|
244 |
results = {}
|
245 |
for rule_name, rule in self.rules.items():
|
246 |
try:
|
247 |
-
# Evaluate the condition using the dataframe 'df'
|
248 |
# **Warning**: Using eval can be dangerous. Ensure that user inputs are sanitized.
|
|
|
249 |
rule_matched = eval(rule.condition, {"__builtins__": None}, {"df": data})
|
250 |
results[rule_name] = {
|
251 |
"rule_matched": rule_matched,
|
@@ -280,10 +285,11 @@ class ClinicalKPIMonitoring:
|
|
280 |
try:
|
281 |
# **Warning**: Using eval can be dangerous. Ensure that user inputs are sanitized.
|
282 |
kpi_value = eval(kpi.calculation, {"__builtins__": None}, {"df": data})
|
|
|
283 |
results[kpi_name] = {
|
284 |
"value": kpi_value,
|
285 |
"threshold": kpi.threshold,
|
286 |
-
"status":
|
287 |
}
|
288 |
except Exception as e:
|
289 |
results[kpi_name] = {"error": str(e)}
|
@@ -448,7 +454,7 @@ class SimpleMedicalKnowledge(MedicalKnowledgeBase):
|
|
448 |
|
449 |
response = f"**Based on your query:** {best_match_info}\n\n"
|
450 |
|
451 |
-
if "No abstracts found for this query on PubMed" not in pubmed_result:
|
452 |
response += f"**PubMed Abstract:**\n{pubmed_result}"
|
453 |
else:
|
454 |
response += f"{pubmed_result}"
|
@@ -468,7 +474,7 @@ class SimpleMedicalKnowledge(MedicalKnowledgeBase):
|
|
468 |
if st.button("Bad Result", key=f"bad_{feedback_key}"):
|
469 |
st.session_state[feedback_key]["feedback"] = "negative"
|
470 |
st.error("Thank you for the feedback!")
|
471 |
-
|
472 |
return response
|
473 |
except Exception as e:
|
474 |
return f"Medical Knowledge Search Failed: {e}"
|
@@ -652,7 +658,6 @@ class DataModelling:
|
|
652 |
|
653 |
def main():
|
654 |
"""Main function to run the Streamlit app."""
|
655 |
-
st.set_page_config(page_title="AI Clinical Intelligence Hub", layout="wide")
|
656 |
st.title("🏥 AI-Powered Clinical Intelligence Hub")
|
657 |
|
658 |
# Initialize Session State
|
@@ -775,6 +780,8 @@ def dataset_metadata_section():
|
|
775 |
"Size": f"{data.memory_usage().sum() / 1e6:.2f} MB"
|
776 |
}
|
777 |
st.json(metadata)
|
|
|
|
|
778 |
|
779 |
def main_tabs_section():
|
780 |
"""Creates and manages the main tabs in the application."""
|
|
|
36 |
try:
|
37 |
nlp = spacy.load("en_core_web_sm")
|
38 |
except OSError:
|
39 |
+
# Use Streamlit's message to inform the user instead of print
|
40 |
st.write("Downloading en_core_web_sm spaCy model...")
|
41 |
spacy.cli.download("en_core_web_sm")
|
42 |
nlp = spacy.load("en_core_web_sm")
|
43 |
|
44 |
+
# ---------------------- Streamlit Page Configuration ---------------------------
|
45 |
+
# This must be the first Streamlit command in the script
|
46 |
+
st.set_page_config(page_title="AI Clinical Intelligence Hub", layout="wide")
|
47 |
+
|
48 |
# ---------------------- Base Classes and Schemas ---------------------------
|
49 |
|
50 |
class ResearchInput(BaseModel):
|
|
|
249 |
results = {}
|
250 |
for rule_name, rule in self.rules.items():
|
251 |
try:
|
|
|
252 |
# **Warning**: Using eval can be dangerous. Ensure that user inputs are sanitized.
|
253 |
+
# Here, we're restricting the environment by removing built-ins.
|
254 |
rule_matched = eval(rule.condition, {"__builtins__": None}, {"df": data})
|
255 |
results[rule_name] = {
|
256 |
"rule_matched": rule_matched,
|
|
|
285 |
try:
|
286 |
# **Warning**: Using eval can be dangerous. Ensure that user inputs are sanitized.
|
287 |
kpi_value = eval(kpi.calculation, {"__builtins__": None}, {"df": data})
|
288 |
+
status = self.evaluate_threshold(kpi_value, kpi.threshold)
|
289 |
results[kpi_name] = {
|
290 |
"value": kpi_value,
|
291 |
"threshold": kpi.threshold,
|
292 |
+
"status": status
|
293 |
}
|
294 |
except Exception as e:
|
295 |
results[kpi_name] = {"error": str(e)}
|
|
|
454 |
|
455 |
response = f"**Based on your query:** {best_match_info}\n\n"
|
456 |
|
457 |
+
if "No abstracts found for this query on PubMed." not in pubmed_result:
|
458 |
response += f"**PubMed Abstract:**\n{pubmed_result}"
|
459 |
else:
|
460 |
response += f"{pubmed_result}"
|
|
|
474 |
if st.button("Bad Result", key=f"bad_{feedback_key}"):
|
475 |
st.session_state[feedback_key]["feedback"] = "negative"
|
476 |
st.error("Thank you for the feedback!")
|
477 |
+
|
478 |
return response
|
479 |
except Exception as e:
|
480 |
return f"Medical Knowledge Search Failed: {e}"
|
|
|
658 |
|
659 |
def main():
|
660 |
"""Main function to run the Streamlit app."""
|
|
|
661 |
st.title("🏥 AI-Powered Clinical Intelligence Hub")
|
662 |
|
663 |
# Initialize Session State
|
|
|
780 |
"Size": f"{data.memory_usage().sum() / 1e6:.2f} MB"
|
781 |
}
|
782 |
st.json(metadata)
|
783 |
+
# Store the selected dataset key in session state for use in analysis
|
784 |
+
st.session_state.selected_data_key = selected_data_key
|
785 |
|
786 |
def main_tabs_section():
|
787 |
"""Creates and manages the main tabs in the application."""
|