A newer version of the Streamlit SDK is available:
1.47.0
title: AI Clinical Intelligence Hub
emoji: π₯
colorFrom: indigo
colorTo: blue
sdk: streamlit
sdk_version: 1.24.1
app_file: app.py
pinned: false
π₯ AI Clinical Intelligence Hub
Welcome to the AI Clinical Intelligence Hub, an advanced, AI-powered platform designed to revolutionize clinical data analysis and decision-making. Leveraging OpenAI's GPT-4, this hub provides comprehensive tools for data ingestion, exploratory data analysis, statistical testing, machine learning model training, clinical rules execution, KPI monitoring, diagnosis support, treatment recommendations, and access to a robust Medical Knowledge Base.
π Features
- Data Ingestion: Seamlessly upload and connect to CSV files or SQL databases.
- Exploratory Data Analysis (EDA): Gain insights into your datasets with comprehensive EDA reports.
- Temporal Pattern Analysis: Analyze time-series data to identify trends and seasonality.
- Comparative Statistics: Perform hypothesis testing and comparative statistical analyses.
- Distribution Analysis: Visualize data distributions using customizable plots.
- Machine Learning: Train and evaluate Logistic Regression models on your data.
- Clinical Rules Engine: Define and execute clinical rules to automate decision-making.
- KPI Monitoring: Define, calculate, and monitor Key Performance Indicators (KPIs).
- Diagnosis Support: Utilize machine learning models to assist in clinical diagnoses.
- Treatment Recommendations: Generate treatment suggestions based on patient data.
- Medical Knowledge Base: Access comprehensive medical information powered by OpenAI's GPT-4 and retrieve relevant PubMed abstracts.
πΈ Screenshots
Dashboard Overview
Medical Knowledge Search Interface
π οΈ Installation & Setup
Deploying the AI Clinical Intelligence Hub on Hugging Face Spaces is straightforward. Follow the steps below to get your application up and running.
1. Prerequisites
- Hugging Face Account: Ensure you have an account on Hugging Face.
- OpenAI API Key: Obtain your API key from OpenAI.
- PubMed Email: A valid email address for accessing PubMed abstracts via Biopython.
2. Clone the Repository
If you haven't already, clone the repository to your local machine:
git clone https://github.com/your-username/ai-clinical-intelligence-hub.git
cd ai-clinical-intelligence-hub
3. Configure Environment Variables
Securely store your OpenAI API key and email address using Hugging Face's Secrets feature.
Navigate to Your Space:
Go to Hugging Face Spaces and create a new Space or select an existing one.
Add Secrets:
Click on the "Settings" tab of your Space.
Scroll down to the "Secrets" section.
Add the following secrets:
OPENAI_API_KEY: Your OpenAI GPT-4 API key.
PUB_EMAIL: Your email address for PubMed access.
Adding Secrets in Hugging Face Spaces
4. Install Dependencies
Ensure all required Python packages are installed. The requirements.txt file includes all necessary dependencies.
bash
Copy
pip install -r requirements.txt
python -m spacy download en_core_web_sm
5. Deploy to Hugging Face Spaces
Push to Repository:
Commit and push your code to your GitHub repository linked to your Hugging Face Space.
bash
Copy
git add .
git commit -m "Fix Altair import and update OpenAI SDK"
git push origin main
Automatic Deployment:
Hugging Face Spaces automatically detects changes and redeploys your application. Monitor the deployment logs for any issues.
π§βπ» Usage
Once deployed, navigate to your Hugging Face Space URL to interact with the AI Clinical Intelligence Hub.
1. Data Management
Upload Data: Use the sidebar to upload CSV files or connect to SQL databases.
Ingest Data: After uploading or connecting, ingest the data to make it available for analysis.
2. Dataset Metadata
View Metadata: Select a dataset to view its metadata, including variables, time ranges, and size.
3. Data Analysis
Select Analysis Mode: Choose from EDA, Temporal Analysis, Comparative Statistics, Distribution Analysis, or Machine Learning.
Perform Analysis: Depending on the selected mode, provide necessary inputs and generate insightful reports and visualizations.
4. Clinical Logic
Define Clinical Rules: Input conditions, actions, and severity levels to automate clinical decision-making.
Define KPIs: Create and monitor Key Performance Indicators relevant to your clinical data.
Execute Rules & Calculate KPIs: Apply defined rules and KPIs to your datasets to obtain actionable insights.
5. Insights
Generate Automated Insights: Select analyses to generate comprehensive insights based on your data.
Diagnosis Support: Utilize machine learning models to assist in clinical diagnoses.
Treatment Recommendations: Generate treatment suggestions based on patient data and conditions.
6. Reports
Create Report Definitions: Define the structure and content of automated reports.
Generate Reports: Produce reports based on predefined definitions and your data.
7. Medical Knowledge
Search Medical Information: Input medical queries to retrieve comprehensive information powered by OpenAI's GPT-4.
PubMed Abstracts: Access relevant PubMed abstracts to supplement medical information.
π API Reference
MedicalKnowledgeBase
search_medical_info(query: str, pub_email: str = "") -> str
Description: Fetches medical information based on user queries using OpenAI's GPT-4 and retrieves relevant PubMed abstracts.
Parameters:
query (str): The medical question or query.
pub_email (str, optional): Email address for PubMed access.
Returns: A formatted string containing the GPT-4 response and PubMed abstract.
ClinicalRulesEngine
add_rule(rule: ClinicalRule)
Description: Adds a new clinical rule to the engine.
execute_rules(data: pd.DataFrame) -> Dict[str, Any]
Description: Executes all defined clinical rules against the provided data.
Parameters:
data (pd.DataFrame): The dataset to apply rules on.
Returns: A dictionary with rule execution results.
ClinicalKPIMonitoring
add_kpi(kpi: ClinicalKPI)
Description: Adds a new KPI to the monitoring system.
calculate_kpis(data: pd.DataFrame) -> Dict[str, Any]
Description: Calculates all defined KPIs based on the provided data.
Parameters:
data (pd.DataFrame): The dataset to calculate KPIs on.
Returns: A dictionary with KPI calculation results.
DiagnosisSupport
diagnose(data: pd.DataFrame, target_col: str, columns: List[str], diagnosis_key: str = "diagnosis", **kwargs) -> pd.DataFrame
Description: Generates diagnosis support based on the data using trained models.
Parameters:
data (pd.DataFrame): The dataset for diagnosis.
target_col (str): The target variable for diagnosis.
columns (List[str]): Feature columns used in the model.
diagnosis_key (str, optional): Key name for the diagnosis result.
Returns: A DataFrame with diagnosis results.
TreatmentRecommendation
recommend(data: pd.DataFrame, condition_col: str, treatment_col: str, recommendation_key: str = "recommendation", **kwargs) -> pd.DataFrame
Description: Provides treatment recommendations based on patient conditions.
Parameters:
data (pd.DataFrame): The dataset containing patient information.
condition_col (str): The column indicating patient conditions.
treatment_col (str): The column indicating available treatments.
recommendation_key (str, optional): Key name for the recommendation result.
Returns: A DataFrame with treatment recommendations.
π¦ Dependencies
The application relies on the following Python packages:
streamlit>=1.24.1
pandas>=1.5.3
numpy>=1.25.2
matplotlib>=3.7.2
seaborn>=0.12.2
scikit-learn>=1.2.2
statsmodels>=0.14.0
pydantic>=2.5.3
biopython>=1.79
python-dotenv>=1.0.0
requests>=2.31.0
spacy>=3.5.3
openai>=1.8.0
altair>=5.1.0
Ensure all dependencies are installed using:
bash
Copy
pip install -r requirements.txt
python -m spacy download en_core_web_sm
π License
This project is licensed under the MIT License.
π Acknowledgments
OpenAI for providing the GPT-4 API.
Biopython for enabling PubMed abstract retrieval.
Streamlit for the intuitive UI framework.
Hugging Face for hosting and deploying the application.
π¬ Contact
For questions, feedback, or support, please reach out to [email protected].
π‘οΈ Security Considerations
API Keys: Ensure that your OPENAI_API_KEY and PUB_EMAIL are stored securely and never exposed in the codebase.
Data Privacy: Comply with relevant data protection regulations (e.g., HIPAA, GDPR) when handling sensitive medical data.
Access Controls: Implement authentication mechanisms if deploying in environments requiring restricted access.
π§© Extending the Application
The AI Clinical Intelligence Hub is designed to be modular and extensible. You can add new data sources, analysis modules, or integrate additional APIs as needed. Contributions and enhancements are welcome!
π€ Contributing
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Feel free to fork the repository and submit pull requests. Please ensure your contributions adhere to the project's coding standards and include relevant tests.
Fork the Project
Create Your Feature Branch (git checkout -b feature/AmazingFeature)
Commit Your Changes (git commit -m 'Add some AmazingFeature')
Push to the Branch (git push origin feature/AmazingFeature)
Open a Pull Request
β FAQs
Q1: How do I obtain an OpenAI API key?
A1: Visit OpenAI's API page to sign up and generate your API key.
Q2: Can I use other machine learning models besides Logistic Regression?
A2: Yes! The framework is designed to be extensible. You can integrate additional models by creating new analyzer classes following the existing structure.
Q3: How does the Medical Knowledge Base handle sensitive queries?
A3: All queries are processed securely using OpenAI's GPT-4 API. Ensure compliance with data protection regulations when handling sensitive information.
π Future Enhancements
User Authentication: Implement robust user authentication and authorization mechanisms.
Advanced Machine Learning Models: Integrate more sophisticated models for diagnosis and prediction.
Real-Time Data Streaming: Support real-time data ingestion and analysis for dynamic clinical environments.
Enhanced Reporting: Develop customizable and exportable report formats (e.g., PDF, DOCX).
Natural Language Processing (NLP): Enhance the Medical Knowledge Base with advanced NLP capabilities for better query understanding.